SpeedBirdNine
SpeedBirdNine

Reputation: 4676

Why doesn't ToString work with Data Binding

Following this example (Example 2) Data Binding works and the UI is updated based on the value of ArtistName.

If xaml binding is written like this:

<Label Grid.Column="1" Grid.Row="1" Content="{Binding}" />

instead of

<Label Grid.Column="1" Grid.Row="1" Content="{Binding ArtistName}" />

then ToString is called on SongViewModel, and even if I override it like this:

 public override String ToString()
 {
     return Song.ArtistName;
 }

the value is not updated through DataBinding. Rest of the code is same as in the example given in the link.

Why doesn't value change in this case?

Upvotes: 1

Views: 1456

Answers (1)

Fede
Fede

Reputation: 44048

WPF Binding doesn't work that way.

If you {Binding} then the only way for WPF to refresh that binding is that you reset the DataContext. That Binding has no PropertyPath to follow therefore INotifyPropertyChanged cannot be called to refresh that kind of Binding.

Upvotes: 2

Related Questions