TreeView is bound to XMLDataProvider - shows data in editor but is empty on startup

I have bound TreeView to XMLDataProvider. The TreeView displays the data as expected in the Visual Studio editor. But when I press F5 the app starts but the treeview is empty. Does anyone know why I can't see it when I start the application?

Here's all the 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"
                    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>

      

+2


source to share


1 answer


I haven't run the code, but I think you need to specify the namespace:

xmlns=""

      



Attach xmlns to the 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>

      

+4


source







All Articles