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?
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.
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.
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
精彩评论