我在将 XmlDataProvider 绑定到 WPF TreeView 时遇到了一些问题。
TreeView 是 XAML 定义的,如下所示:
<TreeView ItemsSource="{Binding Path=SelectedSystemVersionHistory}"/>
我在 XML 文件中的节点的 TreeView 的父网格资源中有一个 HierarchicalDataTemplate:
<HierarchicalDataTemplate DataType="Documentation" ItemsSource="{Binding XPath=*}">
<TextBlock Text="{Binding XPath=@SoftwarePackage}"/>
</HierarchiclaDataTemplate>
我的 ViewModel 有这个属性:
public XmlDataProvider SelectedSystemVersionHistory
{
get
{
String file = GetHistoryFile(); //returns full Filepath
return new XmlDataProvider()
{
source = new Uri(file, UriKind.Absolute),
XPath= "History"
};
}
}
Xml 看起来像这样:
<?xml version="1.0" standalone="yes" encoding="utf-8">
<History>
<Documentation SoftwarePackage="SoftwarePackageName">
<Entry>...</Entry>
</Documentation>
</History>
问题是 TreeView 没有显示任何内容,所以出了什么问题?我已经为此工作了好几天...... :o( 谢谢你的帮助。