0

I have a question to the consequences of the implementation of the INotifyPropertyChanged and properties that are not updating because of the INotifyPropertyChanged.

Let's say I have a Window with a TextBlock and a TextBox. Both are attached to the same property (Text) in my ViewModel.

<TextBlock Grid.Row="0" Text="{Binding Text}"/>
<TextBox Grid.Row="1" Text="{Binding Text}"/>

Scenario 1: The ViewModel does not implement the INotifyPropertyChanged:

If I leave the focus of the TextBox after changing the text, my TextBlock changes the text also.

Scenario 2: The ViewModel does implement the INotifyPropertyChanged:

I didn't fire the PropertyChanged manually. So I understand that my TextBlock does not change the text after changing the text of the TextBox.

But why worked scenario 1 without the INotifyPropertyChanged? ... And why is the same action not working anymore just because of implementing the INotifyPropertyChanged?

Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49

1 Answers1

0

Try this:

<TextBlock Grid.Row="0" Text="{Binding Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
  • Thanks for your answer. Unfortunately your answer does not explaining my phenomenon. – Fruchtzwerg Apr 14 '16 at 18:13
  • 1
    Sorry, I thought you wanted to solve your problem. In Scenario 1, if the textbox changes in code, it wont update the texblock. It works in the visual interface because its part of the default behavior of WPF handling the binding in the UI. When you implement INPC, you have to take care of it. Check this: http://stackoverflow.com/questions/7767218/why-does-the-binding-update-without-implementing-inotifypropertychanged (cant format the link properly cause right now Im using a weird pc with a weird keyboard). Have a good one! – Ricardo Olivo Poletti Apr 14 '16 at 18:36