Silverlight/WP7:
I have a list of objects that I have deserialized from a JSON query. This list will be bound to a ListBox in XAML. However, I want to edit one of the strings that is returned before it gets bound to the UI. I did some searching and I came across this solution, however I am not very clear on the solution proposed:
string _value;
public string Value { get { return _value; } set { _value = value; NotifyPropertyChanged("Value"); NotifyPropertyChanged("ValueFormatted"); } }
public string ValueFormatted { get { return "Static Text: " + _value; } }
What is NotifyPropertyChanged? I am fairly new to Silverlight/C# and I only see the INotifyPropertyChanged interface. How do I implement this solution?
The problem you are trying to solve does not actually require the INotifyPropertyChanged interface. It will work fine if you remove the NotifyPropertyChanged methods and INotifyPropertyChanged interface then bind to the ValueFormatted Property.
However implementing INotifyPropertyChanged on classes being bound to the UI is generally a pretty good idea:
“INotifyPropertyChanged interface is used to notify that a property has been changed and thus to force the bound objects to take the new value.”
This basically means if you change properties of objects after they have been bound the values will be reflected in your UI.
The Silverlight show gives a nice simple example of INotifyPropertyChanged