Application Commands

Application Commands are already implemented commands that are directly provided by the .NET Framework. The .NET Framework offers the following Application Commands that can be found here

The most important of the list, is the Close Command. For those standard commands, no ICommand property has to be created in the view model. The base view model offers a possibility to bind them directly to an Execute and CanExecute method.

Binding Application Commands in the view model
The following Example from the MainWindowViewModelBase class binds the Application Command Close to the view model.
public override void Initialize()
    // This method registers the WPF Command Close
   RegisterApplicationCommand(ApplicationCommands.Close, ExecuteCloseCommand, CanExecuteCloseCommand, true);

Binding Application Commands in XAML
The following example shows how to bind application commands in XAML.
<Button x:Name="CloseButton" 
       Style="{StaticResource ChromeButtonStyle}" 
       <TextBlock TextWrapping="Wrap" Text="r" FontFamily="Webdings" Foreground="#FF919191" FontSize="11" x:Uid="r_TextBlock" />

Important pre-requisites
In order to bind the Application Commands correct, the window or view must reference the helper class RegisterCommandBindings.
Commands:ApplicationCommands.RegisterCommandBindings="{Binding RegisteredCommands}"

Last edited Aug 8, 2012 at 2:59 PM by BitKFu, version 2


No comments yet.