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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:34:11+00:00 2026-06-10T06:34:11+00:00

Recently I got chance to play a little bit with Windows 8 Release Preview

  • 0

Recently I got chance to play a little bit with Windows 8 Release Preview (Build 8400 to be specific). My aim was to investigate bugs which appeared in our product (WPF application) only under Windows 8. The bugs looked very simple – few buttons were disabled when they shouldn’t. It looked easy to fix but I decided to find the root cause.

It turned out that when a control bound to a command receives CanExecuteChanged notification it doesn’t requery command’s CanExecute method if sender is not the same command. This is a bit of a problem in a situation when command performs some operation on a model and it’s ability to execute depends on model’s state. For example, imagine you have a model:

class MyModel
  {
    public void ChangeModel(bool makeValidForCommand)
    {
      Valid = makeValidForCommand;

      if (ModelChanged != null)
        ModelChanged(this, new EventArgs());
    }

    public bool Valid { get; private set; }

    public event EventHandler ModelChanged;
  }

And a command:

class MyCommand : ICommand
  {
    public MyCommand(MyModel model)
    {
      _model = model;
    }

    public bool CanExecute(object parameter)
    {
      return _model.Valid;
    }

    public event EventHandler CanExecuteChanged
    {
      add { _model.ModelChanged += value; }
      remove { _model.ModelChanged -= value; }
    }

    public void Execute(object parameter) { }

    private MyModel _model;
  }

Unfortunately, this won’t work on Windows 8 – the button bound to the command will stay improperly disabled (or enabled) after the model changed state. It works perfectly well on Windows 7 though!

The command can be rewritten like this:

class MyCommand : ICommand
  {
    public MyCommand(MyModel model)
    {
      _model = model;
    }

    public bool CanExecute(object parameter)
    {
      return _model.Valid;
    }

    public event EventHandler CanExecuteChanged
    {
      add
      {
        _canExecuteChanged += value;
        _model.ModelChanged -= _modelChanged;
        _model.ModelChanged += _modelChanged;
      }

      remove
      {
        _canExecuteChanged -= value;
        _model.ModelChanged -= _modelChanged;
      }
    }

    public void Execute(object parameter)
    {
    }

    private void _modelChanged(object sender, EventArgs e)
    {
      if (_canExecuteChanged != null)
        _canExecuteChanged(this, new EventArgs());
    }

    private event EventHandler _canExecuteChanged;
    private MyModel _model;
  }

Now sender is the command itself, and everything is fine. Another option is to use CommandManager and its RequerySuggested event:

public event EventHandler CanExecuteChanged
    {
      add { CommandManager.RequerySuggested += value; }
      remove { CommandManager.RequerySuggested -= value; }
    }

And again it works! Hm, now I’m completely puzzled. Sender is not the command – it’s null, but if I try to send my own event with null sender it doesn’t work again.

Did anyone faced the same? Is it such a strange way of optimization on new Windows? Honestly it looks more like a bug.

  • 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-10T06:34:13+00:00Added an answer on June 10, 2026 at 6:34 am

    Seems, this is a breaking change in .Net Framework 4.5.
    The issue is reported to Microsoft here:

    http://connect.microsoft.com/VisualStudio/feedback/details/751429/wpf-icommand-canexecutechanged-behaviour-change-in-net-4-5

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

Sidebar

Related Questions

I recently got my home PC upgraded to a quad-core CPU and 64-bit OS.
I've recently got the source-code on a application. When im trying to build the
I recently got a situation where I need to set a bit in a
recently got an issue when loading vs 2008, it displays this... can anyone tell
I recently got an email from a customer saying that they were getting errors
I recently got a ssl certificate from godaddy. I created the keystore properly and
We recently got some data back on a benchmarking test from a software vendor,
I recently got into Java. I have a background in dynamic languages and I'm
I recently got a shiny new development workstation. The only disadvantage of this is
I have just recently got involved in a classic ASP.NET project which contains lots

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.