wpf - INotifyPropertyChanged problem -


First of all I want to say that the sample given below is simplification, assuming you have WPF control.

  & lt; Window title = "window 1" height = "300" width = "300" & gt; & Lt; Grid & gt; & Lt; StackPanel & gt; & Lt; Text box text = "{binding name}" margin = "10" /> & Lt; Button horizontal tracing = "center" content = "click me" margin = "5" padding = "2" click = "on buttonclick" /> & Lt; / StackPanel & gt; & Lt; / Grid & gt; & Lt; / Window & gt;  

The window is bound for the person class which implements INotifyPropertyChanged and has a name setter

  public string name { Get {return_name; } Set {_name = "some names"; OnPropertyChanged ("name"); }}  

I.e. _name is assigned "some name" even when the user tries to change it from the UI but this sample does not work. I changed the name for some value in the text box, which is to move the press button to the button Is focusing on and the price remains unchanged in the text box, although the event started by changing the property.

Would you please tell me why this happens? As I have understood that the property changes again reads and displays values ​​from the UI properties in the event forces, but in my example value the data-bound text box is not updated.


I think this is poor implementation of the property, but I repeat that it is overlapping. It is just a sample but anyway, property changes are signs that the property had changed and It should be updated but it should not be.

Changing the property is ignored by the event text box because it is the initiator of the event.

Some explanation:

The text box (or the binding on the text box) knows that it is the beginner because it receives a renamed event for property in the same call. There is no way to know the textbox (or binding) by calling asynchronous call that it is the initiator, so it will process the event as someone else has updated it

If you have 2 text boxes To connect your UI, you will see that when you edit 1, and change the other way, the second text box changes.


Comments