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" />
Binding's property Source can't be bound because it is not a Dependency Property. Are sure you don't want to do this? :
{Binding Path=Data, XPath=*, Converter={StaticResource stringToXmlDataProviderConverter},ConverterParameter=/root}
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With