You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mark Smith edited this page Aug 29, 2016
·
1 revision
SimpleViewModel
The SimpleViewModel class provides a simple base class for the Model-View-ViewModel design pattern. It implements the necessary property change notification support used by the Xamarin.Forms data binding infrastructure. You can use this class as your base class for any view models you create in your app.
Methods
RaiseAllPropertiesChanged : tells any attached bindings that all properties on this instance must be re-evaluated.
RaisePropertyChanged : raises a single property change notification. Has variations for type-safe invocation and string-based invocation.
SetPropertyValue : changes a field value to a new passed value and raises a property change notification if the field was altered. Returns true if the field was changed.
Note: All the methods are protected and intended to be used only by derived classes.
Example
publicclassMyViewModel:SimpleViewModel{publicboolHasText{get{returntext.Length>0;}}privatestringtext="";publicstringText{get{returntext;}set{if(SetPropertyValue(reftext,value)){RaisePropertyChanged(nameof(HasText));// or this if you aren't using C# 6RaisePropertyChanged(()=>HasText);}}}}