HierarchicalDataTemplate and XmlDataProvider : XmlDataProvider « Windows Presentation Foundation « C# / CSharp Tutorial






<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TreeViewSelectedValue">
  <FrameworkElement.Resources>
    <XmlDataProvider x:Key="myCourseData" XPath="/CourseData">
      <x:XData>
        <CourseData xmlns="">
          <CourseInfo>
            <CourseName>A</CourseName>
            <CourseWorkDay>Monday</CourseWorkDay>
            <CourseWorkDay>Tuesday</CourseWorkDay>
            <CourseWorkDay>Wednesday</CourseWorkDay>
            <CourseWorkDay>Thrusday</CourseWorkDay>
            <CourseWorkDay>Friday</CourseWorkDay>
            <CourseStartTime>8:00am</CourseStartTime>
            <CourseNumber>12345</CourseNumber>
          </CourseInfo>
          <CourseInfo>
            <CourseName>B</CourseName>
            <CourseWorkDay>Monday</CourseWorkDay>
            <CourseWorkDay>Tuesday</CourseWorkDay>
            <CourseStartTime>6:30am</CourseStartTime>
            <CourseNumber>98765</CourseNumber>
          </CourseInfo>
        </CourseData>
      </x:XData>
    </XmlDataProvider>
    <HierarchicalDataTemplate DataType="CourseInfo" ItemsSource ="{Binding XPath=CourseWorkDay}">
      <TextBlock Text="{Binding XPath=CourseName}" />
    </HierarchicalDataTemplate>
  </FrameworkElement.Resources>
  <StackPanel>
    <TreeView ItemsSource="{Binding Source={StaticResource myCourseData}, XPath=CourseInfo}" 
        Name="myTreeView" SelectedValuePath="CourseNumber"/>

    <TextBlock Margin="10">SelectedValuePath: </TextBlock>
    <TextBlock Margin="10" Text="{Binding ElementName=myTreeView, Path=SelectedValuePath}"/>
    <TextBlock Margin="10">SelectedValue: </TextBlock>
    <TextBlock Margin="10" Text="{Binding ElementName=myTreeView, Path=SelectedValue}"/>

  </StackPanel>     

</Page>
WPF Hierarchical Data Template And Xml Data Provider








24.149.XmlDataProvider
24.149.1.HierarchicalDataTemplate and XmlDataProviderHierarchicalDataTemplate and XmlDataProvider
24.149.2.Xmldata island.xamlXmldata island.xaml
24.149.3.Hierarchical Xml TemplatesHierarchical Xml Templates
24.149.4.Using XmlDataProviderUsing XmlDataProvider
24.149.5.XmlDataProvider and static Xml resourceXmlDataProvider and static Xml resource
24.149.6.Retrieve data from XmlDataProvider with XPathRetrieve data from XmlDataProvider with XPath
24.149.7.XmlDataProvider and XmlNamespaceMappingXmlDataProvider and XmlNamespaceMapping
24.149.8.XmlDataProvider and ItemsControlXmlDataProvider and ItemsControl
24.149.9.Hyperlink and xpath filter for XmlDataProviderHyperlink and xpath filter for XmlDataProvider
24.149.10.Load XmlDocument to XmlDataProviderLoad XmlDocument to XmlDataProvider
24.149.11.Get XmlElement from Bounded viewGet XmlElement from Bounded view