开发者

TreeView bound to XMLDataProvider - shows data in editor, but empty when run

I have bound a TreeView to an XMLDataProvider. The TreeView displays the data as expected in the Visual Studio editor. But when I press F5, the application runs but the treeview is blank. Does anyone know why I can't see it when I run the application?

Here's the entire code:

<Window x:Class="TreeViewDataBinding.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
    <XmlDataProvider x:Key="FolderList">
        <x:XData>
            <TreeFolders>
                <Folder Name="Audit Reports" />
                <Folder Name="Joes Test" >
                    <Folder Name="Analysis01" />
                    <Folder Name="Test090803" />
                </Folder>
                <Folder Name="Carl" />
                <Folder Name="Steve" />
            </TreeFolders>

        </x:XData>
    </XmlDataProvider>
    <HierarchicalDataTemplate
                    x:Key="FolderTreeItemTemplate"
        开发者_JAVA技巧            DataType="Folder">
        <HierarchicalDataTemplate.ItemsSource>
            <Binding XPath="child::*" />
        </HierarchicalDataTemplate.ItemsSource>
        <TextBlock Text="{Binding XPath=@Name}" />
    </HierarchicalDataTemplate>
        </Window.Resources>
    <Grid>
        <TreeView
            ItemsSource="{Binding Source={StaticResource FolderList}, XPath=//TreeFolders/*}"
            ItemTemplate="{StaticResource FolderTreeItemTemplate}" />
    </Grid>
</Window>


I didn't run the code, but my guess is that you need to specify a namespace:

xmlns=""

Attach xmlns to your fist data tag:

<XmlDataProvider x:Key="FolderList">
    <x:XData>
        <TreeFolders xmlns="">
            <Folder Name="Audit Reports"/>
            <Folder Name="Joes Test">
                <Folder Name="Analysis01"/>
                <Folder Name="Test090803"/>
            </Folder>
            <Folder Name="Carl"/>
            <Folder Name="Steve"/>
        </TreeFolders>
    </x:XData>
</XmlDataProvider>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜