Tony The Lion
Tony The Lion

Reputation: 63240

easiest way to renew Datacontext binding in WPF

What is the fastest way to update my DataContext binding to my WPF usercontrol so that it shows changes in the object it is bound to in the view?

Upvotes: 0

Views: 10567

Answers (3)

Jacob Adams
Jacob Adams

Reputation: 3994

This question here appears to be very similar.

Silverlight: How to force binding after setting the DataContext property

If you don't want to implement the INotifyProperty, you can use my answer and just set the datacontext again

Upvotes: 0

Brian Mains
Brian Mains

Reputation: 50728

Binding an ObservableCollection (which implements a specific interface) with objects that implement INotifyPropertyChanged will immediately show changes to their values in the front end or backend whenever you make changes, as long as the binding modes are set to two way binding.

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564491

The best option is to make your DataContext object implement INotifyPropertyChanged. Make any collections implement INotifyCollectionChanged (ie: use an ObservableCollection<T> instead of List<T>, etc).

If you do this, then the bindings will automatically stay up to date, with no effort on your part.

Upvotes: 4

Related Questions