Reputation: 697
Is it possible for a User control to receive an update whenever a user control changes value? I have a form with a save button and I want to activate it as soon as a value changes.
Currently I am ding this using my View but I have to add a call to every property when it changes. This is OK but for edit boxes it means the user has to tab away before the save button becomes active.
Upvotes: 1
Views: 450
Reputation: 939
If you bind your view to a view model then you can have a flag IsDirty inside view model which will be set every time you fire PropertyChanged event
protected void FirePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
_isDirty = true;
if(handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
Then bind your button with IsDirty
Upvotes: 1
Reputation: 15367
The easiest way is to create a IsDirty boolean property which is changed whenever a value is changed. Couple the IsEnabled property of the save button to the IsDirty boolean.
If it is in a class you want to have to be decoupled, use an event/notification.
Upvotes: 1