TreeView绑定到XMLDataProvider - 在编辑器中显示数据,但在运行时为空 [英] TreeView bound to XMLDataProvider - shows data in editor, but empty when run

查看:175
本文介绍了TreeView绑定到XMLDataProvider - 在编辑器中显示数据,但在运行时为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将TreeView绑定到XMLDataProvider。
TreeView在Visual Studio编辑器中显示预期的数据。但是当我按F5时,应用程序运行,但树视图为空。有谁知道为什么在运行应用程序时看不到它?



这是整个代码:

 < Window x:Class =TreeViewDataBinding.Window1
xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x =http://schemas.microsoft.com/winfx/2006/xaml
Title =Window1Height =300Width =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>


解决方案

我没有运行代码,但我的猜测你需要指定一个命名空间:

  xmlns =
pre>

将xmlns附加到您的拳头数据标签中:

  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>


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"
                    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>

这篇关于TreeView绑定到XMLDataProvider - 在编辑器中显示数据,但在运行时为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆