WPF XmlDataProvider

<Window x:Class="WpfApplication5.Window9"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window9" Height="300" Width="300">
    <Window.Resources>
        <XmlDataProvider x:Key="xdp" XPath="FileSystem/Folder">
            <x:XData>
                <FileSystem xmlns="">
                    <Folder Name="Books">
                        <Folder Name="Programming">
                            <Folder Name="Windows">
                                <Folder Name="WPF" />
                                <Folder Name="MFC" />
                                <Folder Name="Delphi" />
                            </Folder>
                        </Folder>
                        <Folder Name="Tools">
                                <Folder Name="Development" />
                                <Folder Name="Designment" />
                                <Folder Name="Players" />
                            </Folder>
                        </Folder>                    
                </FileSystem>
            </x:XData>
        </XmlDataProvider>
    </Window.Resources>
    <Grid>
        <TreeView ItemsSource="{Binding Source={StaticResource xdp}}">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding XPath=Folder}">
                    <TextBlock Text="{Binding XPath=@Name}" />
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    </Grid>
</Window>

posted @ 2014-11-05 21:54  海阔天空XM  阅读(836)  评论(0)    收藏  举报