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

  • Home
  • SEARCH
  • 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 221959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:04:57+00:00 2026-05-11T19:04:57+00:00

I am applying the MVVM pattern per Josh Smith and having difficulty. I’ve been

  • 0

I am applying the MVVM pattern per Josh Smith and having difficulty. I’ve been researching the problem here and can’t seem to get the syntax quite right.

The code below looks to me like it follows the required syntax, but Visual Studio reports error “Delegate ‘System.Action’ does not take ‘2’ arguments” on the line indicated.

Can someone see where I am making a mistake? Thanks!
+tom

    RelayCommand _relayCommand_MoveUp;
    public ICommand RelayCommand_MoveUp
    {
      get
      {
        if (_relayCommand_MoveUp == null)
        {
          _relayCommand_MoveUp = new RelayCommand(
          (sender, e) => this.Execute_MoveUp(sender, e),     **ERROR REPORTED HERE**
          (sender, e) => this.CanExecute_MoveUp(sender, e));
          return _relayCommand_MoveUp;
        }
      }
    }

    private void Execute_MoveUp(object sender, ExecutedRoutedEventArgs e)
    {
      if (_selectedFolder != null)
      {
        _selectedFolder.SelectParent();
      }
    }

    private void CanExecute_MoveUp(object sender, CanExecuteRoutedEventArgs e)
    {
      e.CanExecute = (_selectedFolder != null) && (_selectedFolder.Parent != null);
        }


//And from Josh Smith:

  public class RelayCommand : ICommand
  {
    public RelayCommand(Action<object> execute);
    public RelayCommand(Action<object> execute, Predicate<object> canExecute);

    public event EventHandler CanExecuteChanged;

    [DebuggerStepThrough]
    public bool CanExecute(object parameter);
    public void Execute(object parameter);
  }
  • 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-05-11T19:04:57+00:00Added an answer on May 11, 2026 at 7:04 pm

    The RelayCommand isn’t a RoutedCommand, which I think is where you ending up confused.

    The constructors for the Relay command take an Action delegate and optional Predicate delegate. These delegates don’t take an EventArgs, just the single Object parameter, which is why you are encountering an error. The predicate also requires a return type of bool, which is the next error you’ll get. In the CanExecute predicate instead of setting e.CanExecute like you do with a RoutedCommand you simply return true/false.

    Here’s how it should look:

    public ICommand RelayCommand_MoveUp
    {
      get
      {
        if (_relayCommand_MoveUp == null)
        {
          _relayCommand_MoveUp = new RelayCommand(Execute_MoveUp, CanExecute_MoveUp);
    
        }
        return _relayCommand_MoveUp;
      }
    }
    
    private void Execute_MoveUp(object sender)
    {
      if (_selectedFolder != null)
      {
        _selectedFolder.SelectParent();
      }
    }
    
    private void CanExecute_MoveUp(object sender)
    {
      return (_selectedFolder != null) && (_selectedFolder.Parent != null);
    }
    

    EDIT (Added from discussion in comments):

    If you want to use something more like the RoutedCommands, which will make the ViewModels more dependent on WPF specific views, there are some good options available.

    This discussion got the whole idea of using RoutedCommands in conjunction with MVVM started.

    And here’s a very solid solution to the issues presented by Josh Smith and Bill Kempf.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As I've been learning WPF, I've been concentrating on applying only the MVVM pattern
I'm using Linq to entities applying a Table per Type approach. This has been
I'm applying the Factory design pattern in my C++ project, and below you can
I have a problem applying the DebuggerDisplay attribute on a generic class: [DebuggerDisplay(--foo--)] class
I think it can be done by applying the transformation matrix of the scenegraph
What is the difference between applying the visitor design pattern to your code and
As applying unit-test to some C code, we run into a problem that some
When applying the MVP pattern to ASP.NET applications, where does using AJAX to post
[SOLVED]: Applying proper list iteration procedure fixed problem. (Shown below) I currently have a
I'm struggling with applying the visitor pattern on some objects that have scalar members

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.