Derik Whittaker

Syndication

News


When Implementing ICommand don’t forget to Hookup RequerySuggested

This post is simply a PSA for the next person who is trying to get up to speed w/ WPF and cannot figure out why your implementation of CanExecute from ICommand is only being called one time.

When you create your command class which implements ICommand and you let VS (or R#) auto-generate your implementation it will only generate the empty EventHandler for CanExecuteChange.  When the empty handler is setup you will not be able to hookup your notification events to allow the ICommand to know to check for CanExecute again.

To resolve this simply hookup the EventHandler as such:

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

After you have setup your handlers correctly your CanExecute logic should start to fire each time the command is updated.

Hope this helps.

Till Next time,


Posted 04-25-2010 12:46 PM by Derik Whittaker
Filed under: ,

[Advertisement]

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)