Whenever you change a property in the data context object (normally this is called a view model), you have to raise a property change.
Your view model class has to look similar as the following
class MyViewModel : INotifyPropertyChanged
{
private int _aValue;
public int AValue {
get { return _aValue; }
set {
if (_aValue != value) {
_aValue = value;
RaisePropertyChanged();
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged([CallerMemberName] string propertyName = "")
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Whenever you change a property you have to call the event handlers of PropertyChanged.
The above solution uses .NET 4.5 CallerMemberName annotation which uses the name of the setter property. When you use .NET 4, just remove the annotation and add the property name as a string.
Further reading:
-
https://msdn.microsoft.com/en-us/library/vstudio/ms743695(v=vs.100).aspx[
^]
- Asking Google "view model property changes"
- Asking Codeproject "wpf viewmodel view"