Tuesday, December 30, 2014

Implementing "IsDirty" for XAML TextBox

I believe the best approach would be to add the IsDirty flag to the ViewModel of the page. So when the bound data is modified IsDirty gets set to true. I guess your ViewModel implements INotifyPropertyChanged so basically whenever you would fire the PropertyChanged Event you would set IsDirty to true. Whenever the data gets saved or reset you would reset it to false.


All your UI logic would work based on the ViewModel (e.g. binding Button states to IsDirty).


The general idea behind using a ViewModel in addition to a model (otherwise you could simply bind the Model-objects to the UI) is to have all necessary logic for the UI behavior and state be encapsulated in the ViewModel.


Hope that helps.


No comments:

Post a Comment