I have a WPF textbox with a binding to the datacontext.
<TextBox Grid.Column="1" Grid.Row="4" Text="{Binding Path=Density,UpdateSourceTrigger=PropertyChanged}"/>
I set the datacontext in the code of a the container control of the textbox (tabItem in this case)
tiMaterial.DataContext = _materials[0];
I also have a listbox with other materials. I want to update the textfield, when another material is selected, hence I code:
private void lbMaterials_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
_material = (Material) lbMaterials.SelectedValue;
tiMaterial.DataContext = _material;
}
The Material class implements the INotifyPropertyChanged interface. I have the two-way update working, it’s just when I change the DataContext, the bindings seem to be lost.
What am I missing?
I tryed to do what you describe in your post but sincerely I didn’t find the problem. In all the cases that I tested my project works perfectly.
I don’t like your solution because I think that MVVM is more clear, but your way works too.
I hope this helps you.
.