Click here to Skip to main content
12,302,514 members (65,320 online)
Click here to Skip to main content

Stats

45K views
881 downloads
38 bookmarked
Posted

Silverlight View Model Communication

, 25 Sep 2010 MIT
An example of Silverlight View Model communication between Master and Child View Models
ViewModelCommunication
ViewModelCommunication.Web
ClientBin
ViewModelCommunication.xap
Bin
Debug
System.Windows.Interactivity.dll
ViewModelCommunication.dll
ViewModelCommunication.xap
Classes
Properties
ViewModelCommunication.csproj.user
ViewModels
Views
using System.Windows.Input;
using System;

// From http://johnpapa.net/silverlight/5-simple-steps-to-commanding-in-silverlight/
namespace ViewModelCommunication
{
    public class DelegateCommand : ICommand
    {
        Func<object, bool> canExecute;
        Action<object> executeAction;
        bool canExecuteCache;

        public DelegateCommand(Action<object> executeAction, Func<object, bool> canExecute)
        {
            this.executeAction = executeAction;
            this.canExecute = canExecute;
        }

        #region ICommand Members

        public bool CanExecute(object parameter)
        {
            bool temp = canExecute(parameter);

            if (canExecuteCache != temp)
            {
                canExecuteCache = temp;
                if (CanExecuteChanged != null)
                {
                    CanExecuteChanged(this, new EventArgs());
                }
            }

            return canExecuteCache;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            executeAction(parameter);
        }

        #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 MIT License

Share

About the Author

defwebserver
Software Developer (Senior) http://ADefWebserver.com
United States United States
Michael Washington is a Microsoft MVP. He is a ASP.NET and
C# programmer.
He is the founder of
LightSwitchHelpWebsite.com

He has a son, Zachary and resides in Los Angeles with his wife Valerie.

He is the Author of:

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160530.1 | Last Updated 25 Sep 2010
Article Copyright 2010 by defwebserver
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid