views:

193

answers:

3

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?

+1  A: 

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.

Reed Copsey
when the data in my datacontext changes, it doesn't show in my view, however I have implemented INotifyPropertyChanged. I am using PRISM.
Tony
Which data in your DataContext? If you're using collections, they must implement INot.CollectionChanged instead of propchanged. Otherwise, this should work, as it's the "standard" way of working in WPF.
Reed Copsey
+1  A: 

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.

Brian
A: 

This question here appears to be very similar.

http://stackoverflow.com/questions/369873/silverlight-how-to-force-binding-after-setting-the-datacontext-property/369989#369989

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

Jacob Adams