First look at an example
Person.cs
Public classperson:observableobject,inotifypropertychanged {Private string_testname; Privateobservablecollection<string> _names=Newobservablecollection<string>(); Public stringtestname {Get { return_testname; } Set{_testname=value; OnPropertyChanged (); } } Publicobservablecollection<string>Names {Get{return_names;} Set{_names=value; raisePropertyChanged (()=Names); } } Public EventPropertyChangedEventHandler propertychanged; protected Virtual voidOnPropertyChanged ([Callermembername]stringPropertyName =NULL) {PropertyChangedEventHandler handler=propertychanged; if(Handler! =NULL) {Handler ( This,NewPropertyChangedEventArgs (PropertyName)); } } }
MainWindow.xaml.cs
Public Partial classMainwindow:window, INotifyPropertyChanged {Private int_currentid; PrivatePerson _person; PublicPerson person {Get { return_person; } Set{_person=value; OnPropertyChanged (); } } PublicMainWindow () {InitializeComponent (); This. DataContext = This; person=NewPerson (); Person.testname="testname"; PERSON.NAMES.ADD ("string"); _currentid=Thread.CurrentThread.ManagedThreadId; Dispatcherhelper.initialize (); } Public EventPropertyChangedEventHandler propertychanged; protected Virtual voidOnPropertyChanged ([Callermembername]stringPropertyName =NULL) {PropertyChangedEventHandler handler=propertychanged; if(Handler! =NULL) {Handler ( This,NewPropertyChangedEventArgs (PropertyName)); } } Private voidButtonbase_onclick (Objectsender, RoutedEventArgs e) {Task.Factory.StartNew ()= { if(_currentid = =Thread.CurrentThread.ManagedThreadId) { person=NewPerson (); } Else { //do you think the attributes can be updated to the interface? Person.testname ="Notsame"; //What about the collection? PERSON.NAMES.ADD ("Hello"); } }); } }
Note where the notes are
The result is that the TestName property can be correctly updated to the UI, and the collection properties names not (there is really no understanding, asking for it).
The rest of the understanding, there is an article well written
Http://www.cnblogs.com/wpcockroach/p/3909081.html
WPF Binding inotifypropertychanged Multithreading in-depth understanding