In this article, we will demonstrate how to develop MVVM in Windows 8, and first we prepare two auxiliary classes as follows:
Viewmodebase class:
public class viewmodebase:inotifypropertychanged
{public
event PropertyChangedEventHandler propertychanged ;
<summary>
Triggering event when///property changes
///</summary>
///<param name= "PropertyName" ></param >
protected void OnPropertyChanged (String propertyname)
{
var handler = this. propertychanged;
if (handler!= null)
{
handler (this, new PropertyChangedEventArgs (PropertyName));
}
}
Delegatecommand class:
public class Delegatecommand:icommand {private readonly Action m_exeaction;
Private ReadOnly func<bool> m_canexeaction; <summary>///Constructor///</summary>///<param name= "ExecuteAction" ></param >///<param name= "canexecuteaction" ></param> public Delegatecommand (Action executeAction,
Func<bool> canexecuteaction) {m_exeaction = executeAction;
M_canexeaction = canexecuteaction; }///<summary>///constructors///</summary>///<param name= "executeAction "></param>///<param name=" canexecuteaction "></param> public Delegatecommand (Action ExecuteAction): This (executeAction, null) {}///<summary>///to determine whether or not to perform the exercise As///</summary>///<param name= "parameter" ></param> <returns></returns> public bool CanExecute (object parameter) {if (m_canexeact
Ion!= null) {return m_canexeaction ();
return true; ///<summary>//////</summary> public event EventHandler CanE If a change occurred for the operation was performed
xecutechanged; <summary>///the contents of the action can be changed to action action///</summary>///<param name= "parameter" &G
t;</param> public void Execute (object parameter) {if (CanExecute (parameter))
{m_exeaction (); } protected void Oncanexecutechanged (object sender, EventArgs args) {var handl
ER = canexecutechanged;
if (handler!= null) {handler (this, eventargs.empty); }} public void RaisecanexecutechaNged () {oncanexecutechanged (this, eventargs.empty); }
}