Click here to Skip to main content
11,629,614 members (60,310 online)
Click here to Skip to main content
Add your own
alternative version

Modeling M-V-VM

, 5 Jun 2009 CPOL 16.7K 284 23
An article which tries to present an approach for decoupling M-V-VM View Model objects
TestTreeViewWithLeftBarView.zip
TestTreeViewWithLeftBarView
bin
Debug
TestTreeViewWithLeftBarView.exe
TestTreeViewWithLeftBarView.vshost.exe
TestTreeViewWithLeftBarView.vshost.exe.manifest
WorldDataLib.dll
Properties
Settings.settings
Resources
Service References
WorldServiceReference
configuration.svcinfo
configuration91.svcinfo
Reference.svcmap
service.wsdl
View
ViewModel
WorldDataLib
bin
Debug
WorldDataLib.dll
Model
Properties
WorldServiceApp
bin
Debug
WorldDataLib.dll
WorldServiceApp.exe
WorldServiceApp.vshost.exe
WorldServiceApp.vshost.exe.manifest
WorldServiceLib.dll
Properties
WorldServiceLib
bin
Debug
WorldDataLib.dll
WorldServiceLib.dll
Properties
WorldServiceLib.csproj.user
Modeled_ViewModel.suo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace TestTreeViewWithRightBarView.ViewModel
{
    public class DelegateCommand : ICommand
    {

        #region Helper Objects

        public delegate void SimpleEventHandler();

        #endregion

        #region Events

        public event EventHandler CanExecuteChanged;

        #endregion

        #region Members

        SimpleEventHandler m_Handler;
        bool m_bEnabled;

        #endregion        

        #region Methods

        #region Ctor

        public DelegateCommand(SimpleEventHandler handler)
        {
            this.m_Handler = handler;
            m_bEnabled = true;
        }

        #endregion

        private void OnCanExecuteChanged()
        {
            if (this.CanExecuteChanged != null)
            {
                this.CanExecuteChanged(this, EventArgs.Empty);
            }
        }

        bool ICommand.CanExecute(object arg)
        {
            return this.IsEnabled;
        }

        void ICommand.Execute(object arg)
        {
            this.m_Handler();
        }

        public bool IsEnabled
        {
            get
            {
                return this.m_bEnabled;
            }

            set
            {
                this.m_bEnabled = value;
                this.OnCanExecuteChanged();
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Izhar Lotem
Software Developer
Israel Israel
Software Developer in a promising Clean-Tech company

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150723.1 | Last Updated 5 Jun 2009
Article Copyright 2009 by Izhar Lotem
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid