A“绑定”无法在“源”上设置“Binding”类型的属性
无法在“Binding”类型的“Source”属性上设置“Binding”。 “绑定”只能在 DependencyObject 的 DependencyProperty 上设置。
<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 = "
"1 2 3
我尝试使用 此代码示例。 不同之处在于我想将 ItemsSource 绑定到 datacontext 中的数据。 转换器没有任何问题。
编辑:
<TreeViewItem ItemsSource="{Binding Path=Data}" Header="Parameters" />
用一个元素(字符串)填充 TreeView。所以数据上下文是正确的。
编辑: 这段代码效果更好。有没有一种通用的方法可以在 ThreeView 中读取 XML?我不知道XML的结构。在我看到的所有示例中,您都必须声明子节点类型。
<TreeViewItem DataContext="{Binding Path=Data, Converter={StaticResource stringToXmlDataProviderConverter}}" ItemsSource="{Binding .}" Header="Parameters" />
A 'Binding' cannot be set on the 'Source' property of type 'Binding'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.
<TreeView Height="400" Width="400">
<TreeViewItem ItemsSource="{Binding Source={Binding Path=Data}, XPath=*,
Converter={StaticResource stringToXmlDataProviderConverter},ConverterParameter=/root }" Header="header" />
</TreeView>
What is wrong with ItemsSource="{Binding Source={Binding Path=Data}?
Data = "<root><parm1>1</parm1><parm2>2</parm2><parm3>3</parm3></root>"
I try to use this code sample.
The differ is that I want to Bind the ItemsSource to data in datacontext.
There is nothing wrong with the converter.
EDIT:
<TreeViewItem ItemsSource="{Binding Path=Data}" Header="Parameters" />
Fills TreeView with one element (the string). So datacontext is correct.
EDIT:
This code works better. Is there a generic way to read XML in ThreeView? I don't know the structure of XML. In all examples I have seen you have to declare sub nodes types.
<TreeViewItem DataContext="{Binding Path=Data, Converter={StaticResource stringToXmlDataProviderConverter}}" ItemsSource="{Binding .}" Header="Parameters" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
绑定的属性 Source 无法绑定,因为它不是依赖属性。您确定不想这样做吗? :
编辑:
调试绑定时检查的清单:
1)您是否正确设置了 DataContext?
2) 该属性对 XAML 代码是否可见?
3) 属性是否被访问(在其 getter 中放置一个断点)。它返回它应该返回的值吗?
4) 属性更新是否正确?必须应用以下任一场景:
该属性是 DependecyProperty
该属性通知有关
其更改通过 INotofyPropertyChanged
我们最终确定的属性值
在调用InitializeComponent()之前
Binding's property Source can't be bound because it is not a Dependency Property. Are sure you don't want to do this? :
EDIT:
A checklist to check while debugging bindings:
1) Have you correctly set DataContext?
2) Is the property visible to the XAML code?
3) Is the property accessed (put a breakpoint into its getter). Does it return the value it is supposed to?
4) Is the property updated correctly? Either of following scenarios must apply:
The property is DependecyProperty
The property notifies about
its change via INotofyPropertyChanged
The property value us finalized
before calling InitializeComponent()