florian2905
florian2905

Reputation: 21

Binding issue after data context changed

I have a strange problem: I have a WPF screen on which I have an extended TextBox that makes some conversions in some cases and that property is bound to a property on view model. When the data context is changed the conversions are reevaluated. When reevaluated my extended TextBox has the new data context but the BindingOperations.GetBindingExpression(textBox, dpproperty).DataItem is still the old data context. Maybe the conversion that I make is too early after changind the data context? Usually the data context is not changed into the whole screen so the bindings to be reevaluated? Thanks!

Upvotes: 2

Views: 1593

Answers (1)

DHN
DHN

Reputation: 4865

Well the problem is, that the bindings of the view do not notice that the DataContext is changed. So they are still 'looking' on the VM which was assigned first.

So the best way, to solve the issue is to change the data in the VM assigned as DataContext instead of assigning another instance. Since the VM should implement INotifyPropertyChanged the bindings will update automatically.

Upvotes: 0

Related Questions