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 1017305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:40:58+00:00 2026-05-16T10:40:58+00:00

I am reading Josh Smith’ WPF Apps With The Model-View-ViewModel Design Pattern tutorial i

  • 0

I am reading Josh Smith’ WPF Apps With The Model-View-ViewModel Design Pattern tutorial

i don’t understand what the below code is trying to do.
First, the syntax reminds me properties, but with add/remove instead.

But what is CommandManager.RequerySuggested?

It delegates the event subscription to
the CommandManager.RequerySuggested
event. This ensures that the WPF
commanding infrastructure asks all
RelayCommand objects if they can
execute whenever it asks the built-in
commands

//Figure 3 The RelayCommand Class
public class RelayCommand : ICommand 
{ 
#region Fields 
    readonly Action<object> _execute; 
    readonly Predicate<object> _canExecute; 
#endregion // Fields
#region Constructors 
public RelayCommand(Action<object> execute) : this(execute, null) 
{ } 
public RelayCommand(Action<object> execute, Predicate<object> canExecute) 
{ 
    if (execute == null) throw new ArgumentNullException("execute"); 
   _execute = execute; 
   _canExecute = canExecute; 
} 
#endregion // Constructors 
#region ICommand Members 
[DebuggerStepThrough] 
public bool CanExecute(object parameter) 
{ 
    return _canExecute == null ? true : _canExecute(parameter); 
} 
public event EventHandler CanExecuteChanged 
{ 
    add    { CommandManager.RequerySuggested += value; } 
    remove { CommandManager.RequerySuggested -= value; } 
} 
public void Execute(object parameter) 
{ _execute(parameter); } 
#endregion // ICommand Members }

Also, save command is configured with lambdas. 1st, there are 2 param variables.
Will they conflict? i cannot just do something like RelayCommand(this.Save(), this.CanSave) or is there no such syntax.

_saveCommand = new RelayCommand(param => this.Save(),
                                param => this.CanSave );
  • 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-16T10:40:59+00:00Added an answer on May 16, 2026 at 10:40 am
    1. CommandManager.RequerySuggested += value means that if the function for CanExecute can resolve to both true and false depending on some conditions.

      WPF will disable the Button/MenuItem (CommandButtonBase) if it evaluates to false and enable whenever the condition evaluates to true.
      If you don’t have those two lines, WPF will ask the command only once (when the Button/MenuItem is loaded and will not update after that unless you do it manually.

    2. The two parameters (lambda-expressions) are of type Action<object> and a Predicate<object> respectively. So, they cannot, by definition, conflict (params is just a name – and as the two functions have different scope – they don’t conflict).

      If you have a method with the right signature, you can use that in the constructor

      • private void Save(object obj)
        and
        private bool CanSave(object obj)

      respectively, but you shouldn’t have the () at the end – so new RelayCommand(this.Save,this.CanSave) should work.

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

Sidebar

Related Questions

I've just been reading Josh Smith's MVVM article and am working on a WPF
I was reading a blog entry by Josh Smith where he used a cache
As many others, I started my MVVM journey by reading Josh Smith's MVVM Demo.
Reading about the Dispose pattern , I see the documentation repeatedly refer to cleaning
Reading the Python 3.2 tutorial here , towards the end one of the examples
reading this https://developers.google.com/in-app-payments/docs/tutorial Quoted from the above page: Because you sign the JWT using
Reading for hours, I am pretty sure I understand how blocks in Jade work.
Reading the design guidelines. I came across a little issue while trying to practice
I've been reading Josh Bloch's 'Effective Java 2nd Edition'. Item 43 states 'Return empty
Reading the article on http://www.jamesward.com/2011/08/23/war-less-java-web-apps on how to embed an app server with your

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.