Is it possible to update the data context of a WPF control in a thread other than the UI?
Let's say we have Labelone that has MyClassboth a data context and binds Contentto MyProperty:
Label
MyClass
Content
MyProperty
<Label Name="label" Content="{Binding MyProperty}" />,
<Label Name="label" Content="{Binding MyProperty}" />
where is MyClasssimple:
public class MyClass : INotifyPropertyChanged { int _myField; public int MyProperty { get { return _myField; } set { _myField = value; PropertyChanged(this, new PropertyChangedEventArgs("MyProperty")); } } public event PropertyChangedEventHandler PropertyChanged; }
In a thread other than the UI, we can do myClass.MyProperty = "updated"to update the contents of the label, but we can not do label.Content = "updated"directly. It is right?
myClass.MyProperty = "updated"
label.Content = "updated"
My own answer :
Here is what I found:
ObserverableCollection
, . ( CollectionChanged ).
CollectionChanged
ObservableCollection<T> . , UI, , , (ObservableCollection<T> , ). , ObservableCollection<T>, ( ).
ObservableCollection<T>