WPF Command Example

I've worked up a simple example of how to use Commands in WPF.  This example includes:

  • Creating custom Commands
  • Using built-in and custom Commands in XAML
  • Shows how to use Commands in menus, toolbars, buttons and context menus
  • Shows how the CanExecute call back is used to enable/disable multiple XAML elements that are tied to the same Command
  • Shows how to use Parameterized Commands

Please let me know what you think of the sample.

Comments:

Gravatar

Great example. I like the simplicity

Gravatar

The link to the zipped example is broken.

Gravatar

Kasimier,

Sorry should work now...

Gravatar

Hi Shawn,

I realise this is a bit old now, but I just downloaded it and had a question.

I notice that your "owner type" for the commands is "Window1", despite the fact that the commands are defined in their own class. Is there any reason behind this, or would it be safe to change the owner type to "typeof(MyCommands)"? The app seems to work fine having done so.

Cheers,
Matt

Gravatar

Great example of how to use Commands. Thanks for putting this together, it helped me a lot!


 



 
Save Cancel