C# A';装订';无法在';来源';类型为'的属性;装订';
无法在“Binding”类型的“Source”属性上设置“Binding”。只能对DependencyObject的DependencyProperty设置“绑定”C# A';装订';无法在';来源';类型为'的属性;装订';,c#,wpf,xaml,binding,C#,Wpf,Xaml,Binding,无法在“Binding”类型的“Source”属性上设置“Binding”。只能对DependencyObject的DependencyProperty设置“绑定” <TreeView Height="400" Width="400"> <TreeViewItem ItemsSource="{Binding Source={Binding Path=Data}, XPath=*, Converter={StaticResource stringToXmlDat
<TreeView Height="400" Width="400">
<TreeViewItem ItemsSource="{Binding Source={Binding Path=Data}, XPath=*,
Converter={StaticResource stringToXmlDataProviderConverter},ConverterParameter=/root }" Header="header" />
</TreeView>
- ItemsSource=“{Binding Source={Binding Path=Data}有什么问题?
Data = "<root><parm1>1</parm1><parm2>2</parm2><parm3>3</parm3></root>"
Data=“123”
<TreeViewItem ItemsSource="{Binding Path=Data}" Header="Parameters" />
用一个元素(字符串)填充TreeView。因此datacontext是正确的
编辑:
这段代码效果更好。有没有一种在ThreeView中读取XML的通用方法?我不知道XML的结构。在我看到的所有示例中,您都必须声明子节点类型
<TreeViewItem DataContext="{Binding Path=Data, Converter={StaticResource stringToXmlDataProviderConverter}}" ItemsSource="{Binding .}" Header="Parameters" />
无法绑定绑定的属性源,因为它不是依赖项属性。确实不想这样做吗?:
{Binding Path=Data, XPath=*, Converter={StaticResource stringToXmlDataProviderConverter},ConverterParameter=/root}
编辑:
调试绑定时要检查的清单:
1) 您是否正确设置了DataContext
2) 该属性对XAML代码可见吗
3) 属性是否被访问(将断点放入其getter中)。它是否返回它应该返回的值
4) 属性是否已正确更新?必须应用以下任一情况:
- 该财产为从属财产
- 该属性通知 其通过inotofyproperty的更改已更改
- 我们最终确定了财产价值 在调用InitializeComponent()之前