Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8412565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:42:10+00:00 2026-06-10T00:42:10+00:00

Abstracting commands into the View Model is a valuable practice with XAML/MVVM projects. I

  • 0

Abstracting commands into the View Model is a valuable practice with XAML/MVVM projects. I get that. And, I see ICommand in in WinRT; but, how do we implement it? I haven’t found a sample that actually works. Anyone know?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:42:12+00:00Added an answer on June 10, 2026 at 12:42 am

    My all time favorite has to be the DelegateCommand provided by the Microsoft Patterns and Practices team. It allows you to create a typed command:

    MyCommand = new DelegateCommand<MyEntity>(OnExecute);
    ...
    private void OnExecute(MyEntity entity)
    {...}
    

    It also provides a way to raise the CanExecuteChanged event (to disable/enable the command)

    MyCommand.RaiseCanExecuteChanged();
    

    Here’s the code:

    public class DelegateCommand<T> : ICommand
    {
        private readonly Func<T, bool> _canExecuteMethod;
        private readonly Action<T> _executeMethod;
    
        #region Constructors
    
        public DelegateCommand(Action<T> executeMethod)
            : this(executeMethod, null)
        {
        }
    
        public DelegateCommand(Action<T> executeMethod, Func<T, bool> canExecuteMethod)
        {
            _executeMethod = executeMethod;
            _canExecuteMethod = canExecuteMethod;
        }
    
        #endregion Constructors
    
        #region ICommand Members
    
        public event EventHandler CanExecuteChanged;
    
        bool ICommand.CanExecute(object parameter)
        {
            try
            {
                return CanExecute((T)parameter);
            }
            catch { return false; }
        }
    
        void ICommand.Execute(object parameter)
        {
            Execute((T)parameter);
        }
    
        #endregion ICommand Members
    
        #region Public Methods
    
        public bool CanExecute(T parameter)
        {
            return ((_canExecuteMethod == null) || _canExecuteMethod(parameter));
        }
    
        public void Execute(T parameter)
        {
            if (_executeMethod != null)
            {
                _executeMethod(parameter);
            }
        }
    
        public void RaiseCanExecuteChanged()
        {
            OnCanExecuteChanged(EventArgs.Empty);
        }
    
        #endregion Public Methods
    
        #region Protected Methods
    
        protected virtual void OnCanExecuteChanged(EventArgs e)
        {
            var handler = CanExecuteChanged;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    
        #endregion Protected Methods
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for Linux, there is a nifty little library called xbindkeys that (surprise) binds commands
Using vanilla WPF (no MVVM framework like Prism). Let me say up front that
Some of my recent web projects that I worked on, use a flow engine
So far I've tried the following commands: sudo apt-get remove mysql-server mysql-client mysql-common sudo
We seems to be abstracting a lot of logic way from web pages and
I like the idea of abstracting CellControllers in a heterogeneous UITableView as suggested by
I work with an OO database abstraction layer that I wrote. I have parameters
When using SQL Alchemy for abstracting your data access layer and using controllers as
Sorry for this english related question but I only came across that expression in
Well I want to send commands and data between client and server. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.