![](/img/trans.png)
[英]A 'Binding' cannot be set on the 'Headers' property of type 'MiniListView'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject
[英]A 'Binding' cannot be set on the 'Source' property of type '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 = "<root><parm1>1</parm1><parm2>2</parm2><parm3>3</parm3></root>"
我嘗試使用此代碼示例。 不同之處在於我想將ItemsSource綁定到datacontext中的數據。 轉換器沒有錯。
編輯:
<TreeViewItem ItemsSource="{Binding Path=Data}" Header="Parameters" />
用一個元素(字符串)填充TreeView。 因此,datacontext是正確的。
編輯:此代碼效果更好。 有沒有在ThreeView中讀取XML的通用方法? 我不知道XML的結構。 在所有示例中,我都看到您必須聲明子節點類型。
<TreeViewItem DataContext="{Binding Path=Data, Converter={StaticResource stringToXmlDataProviderConverter}}" ItemsSource="{Binding .}" Header="Parameters" />
綁定的屬性Source不能綁定,因為它不是依賴項屬性。 確定您不想這樣做嗎? :
{Binding Path=Data, XPath=*, Converter={StaticResource stringToXmlDataProviderConverter},ConverterParameter=/root}
編輯:
調試綁定時要檢查的清單:
1)您是否正確設置了DataContext?
2)該屬性對XAML代碼可見嗎?
3)是否訪問了屬性(將斷點放入其getter中)。 它是否返回應有的值?
4)屬性是否正確更新? 必須采用以下兩種情況之一:
該屬性是DependecyProperty
該屬性通過INotofyPropertyChanged通知其更改
我們在調用InitializeComponent()之前確定的屬性值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.