The following DataTemplate.DataTrigger makes the age display red if it is equal to 30.
How do I make the age display red if it is
I believe there is a simpler way of acheiving the goal by using the powers of MVVM and INotifyPropertyChanged.
With the Age property create another property which will be a boolean called IsAgeValid. The IsAgeValid will simply be an on demand check which does not technically need an the OnNotify call. How?
To get changes pushed to the Xaml, place the OnNotifyPropertyChanged event to be fired for IsAgeValid within the Age setter instead.
Any binding to IsAgeValid will also have a notify message sent on any Age change subscriptions; which is what really is being looked at...
Once setup, of course bind the style trigger for false and true accordingly to the IsAgeValid result.
public bool IsAgeValid{ get { return Age > 30; } }
public int Age
{
get { return _Age; }
set
{
_Age=value;
OnPropertyChanged("Age");
OnPropertyChanged("IsAgeValid"); // When age changes, so does the
// question *is age valid* changes. So
// update the controls dependent on it.
}
}