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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:22:26+00:00 2026-06-07T11:22:26+00:00

I am trying to create a WPF application taking advantage of Commands but I

  • 0

I am trying to create a WPF application taking advantage of Commands but I am having an issue with commands enabling menu buttons. I am doing some simple validation, in this case, the “Save” button is disabled until the user creates a new document or loads an existing one.

Lets say my View Model looks like this where the object ViewModel inherits INotifyPropertyChanged:

public ViewModel()
{
    New = new RelayCommand( OnNew, CanNew );
    Save = new RelayCommand( OnSave, CanSave );
}

ICommand m_cmdNew;

public ICommand New
{
    get { return m_cmdNew; }
    set
    {
        m_cmdNew = value;
        OnPropertyChanged( "New" );
    }
}

void OnNew( object param )
{
    bCanSave = true;
    // I read that this could resolve my problem.
    CommandManager.InvalidateRequerySuggested();
}

bool CanNew(  object param )
{
    return true;
}

Lets assume I am doing the same thing for a “Save” Command as well, the only exception being the “CanSave” looks like this:

bool CanSave( object param )
{
    return bCanSave;
}

My Xaml:

<Menu>
    <MenuItem Header="Text">
        <MenuItem Header="New" Command="{Binding New}"/>
        <MenuItem Header="Save" Command="{Binding Save}"/>
    </MenuItem>
</Menu>

The problem that I am having is that the CanSave method is never called after I change the variable “bCanSave”. How can I accomplish this? I know I can simply create a property and using INotifyPropertyChanged and XAML binding, I can simply toggle the IsEnabled property, but that seems like a lot of work when from what I read, commands already do this.

  • 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-07T11:22:28+00:00Added an answer on June 7, 2026 at 11:22 am

    You need to raise the CanExecuteChanged event on the command you want reevaluated, in this case that should be done when that horrible hungarian bool changes.

    (I would recommend making the command fields readonly and the properties get-only, commands don’t usually change)

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

Sidebar

Related Questions

I'm trying to create a simple toolbar in WPF, but the toolbar shows up
I am trying to create a WPF database application. There seems to be a
I have a WPF application where I'm trying to create a diagnostics panel that's
I am trying to create a user control within a WPF application that will
I'm trying to create a transparent ListBox in a WPF application. I want the
I am trying to create a parent WPF/surface application which will host multiple WPF/surface
I am trying to create a file system when installing a WPF application. Currently
I am trying to create a WPF application that takes command line arguments. If
I am trying to create a WPF application that will be a central point
I'm trying to create my own Media Player application using a WPF MediaElement. I

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.