WPF nested data binding works randomly
I have a simple form with several te开发者_JAVA技巧xtboxes. I am using a ViewModel as DataContext set from code. In the ViewModel I have a property with name Metadata. This propery changes as the user loads new "Metadata" into the form.
The textbox XAML looks like this:
<TextBox Text="{Binding Path=Metadata.ContractMetadata.Utstrackning.VastligasteLongitud, Mode=TwoWay}" />
In the ViewModel when the Metadata property is changed I run OnProperyChanged("Metadata"). Metadata implements the INotifyPropertyChanged interface, the other classes in the hierarchy does not. Sometimes it works, other times it does not. I have tried running:
OnProperyChanged("Metadata")
OnProperyChanged("Metadata.ContractMetadata");
OnProperyChanged("Metadata.ContractMetadata.Utstrackning");
OnProperyChanged("Metadata.ContractMetadata.Utstrackning.VastligasteLongitud");
...with no luck.
ProperyChanged for nested properties is not done the way you are doing it!
Each nested level instance must raise a property changed notification itself.
e.g. Metadata instance should raise "ContractMetadata" property
ContractMetadata instance should raise "Utstrackning" property
and Utstrackning instance should raise "VastligasteLongitud" property.
Did you try NotifyPropertyChanged("...") ?
精彩评论