Hierarchical Xml Templates : XmlDataProvider « Windows Presentation Foundation « C# / C Sharp






Hierarchical Xml Templates

Hierarchical Xml Templates
   
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Authors and Their Books">
    <Page.Resources>
        <XmlDataProvider x:Key="data" XPath="Authors">
            <x:XData>
                <Authors xmlns="">
                    <Author Name="Jane Austen">
                        <BirthDate>1972</BirthDate>
                        <DeathDate>2010</DeathDate>
                        <Books>
                            <Book Title="A">
                                <PubDate>2003</PubDate>
                            </Book>
                            <Book Title="B">
                                <PubDate>1813</PubDate>
                            </Book>
                        </Books>
                    </Author>
                </Authors>
            </x:XData>
        </XmlDataProvider>
        <HierarchicalDataTemplate DataType="Author" ItemsSource="{Binding XPath=Books/Book}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding XPath=@Name}" />
                <TextBlock Text=" (" />
                <TextBlock Text="{Binding XPath=BirthDate}" />
                <TextBlock Text="-" />
                <TextBlock Text="{Binding XPath=DeathDate}" />
                <TextBlock Text=")" />
            </StackPanel>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="Book">
            <StackPanel Orientation="Horizontal" TextBlock.FontSize="10pt">
                <TextBlock Text="{Binding XPath=@Title}" />
                <TextBlock Text="{Binding XPath=PubDate}" />
            </StackPanel>
        </HierarchicalDataTemplate>
    </Page.Resources>
    <TreeView ItemsSource="{Binding Source={StaticResource data}, XPath=Author}" />
</Page>

   
    
    
  








Related examples in the same category

1.HierarchicalDataTemplate and XmlDataProviderHierarchicalDataTemplate and XmlDataProvider
2.Xmldata island.xamlXmldata island.xaml
3.Using XmlDataProviderUsing XmlDataProvider
4.XmlDataProvider and static Xml resourceXmlDataProvider and static Xml resource
5.Retrieve data from XmlDataProvider with XPathRetrieve data from XmlDataProvider with XPath
6.XmlDataProvider and XmlNamespaceMappingXmlDataProvider and XmlNamespaceMapping
7.XmlDataProvider and ItemsControlXmlDataProvider and ItemsControl
8.Hyperlink and xpath filter for XmlDataProviderHyperlink and xpath filter for XmlDataProvider
9.Load XmlDocument to XmlDataProviderLoad XmlDocument to XmlDataProvider
10.Get XmlElement from Bounded viewGet XmlElement from Bounded view