Getting Started with Windows 8 Development (21) MVVM Development under Windows 8

Source: Internet
Author: User
Tags bool

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); }
    }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.