1 <!-- <SnippetCustomCommandMapping-->
2 <Window x:Class="SDKSample.Window1"
3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5 xmlns:custom="clr-namespace:SDKSample"
6 Title="Custom RoutedCommand Sample"
7 Name="RootWindow" Height="500" Width="600"
9 <!-- </SnippetCustomCommandMapping-->
10 <Window.CommandBindings>
11 <CommandBinding Command="{x:Static custom:Window1.ColorCmd}"
12 Executed="ColorCmdExecuted"
13 CanExecute="ColorCmdCanExecute"/>
14 </Window.CommandBindings>
16 <Menu DockPanel.Dock="Top"
18 <MenuItem Header="Commands">
19 <MenuItem Header="Color Command"
20 Command="{x:Static custom:Window1.ColorCmd}" />
23 <Border BorderBrush="Black" BorderThickness="1" Margin="10"
24 Height="175" Width="375" DockPanel.Dock="Top">
25 <TextBlock TextWrapping="Wrap" Margin="3">
26 The Color Command chages the background color of a StackPanel.
29 In order for the command attached to the MenuItem to be enabled, the
30 StackPanel must have keyboard focus. Use the TAB key to change focus.
33 Since the command attached to the Button has the CommandTarget
34 set to the first StackPanel, the StackPanel does not need focus.
38 <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"
39 DockPanel.Dock="Bottom">
40 <Border BorderBrush="Black" BorderThickness="1" Margin="10"
41 Height="200" Width="200">
42 <StackPanel Name="FirstStackPanel"
43 Background="AliceBlue"
45 <StackPanel.CommandBindings>
46 <CommandBinding Command="{x:Static custom:Window1.ColorCmd}"
47 Executed="ColorCmdExecuted"
48 CanExecute="ColorCmdCanExecute"/>
49 </StackPanel.CommandBindings>
51 <Label>First StackPanel</Label>
53 <Button Command="{x:Static custom:Window1.ColorCmd}"
54 CommandParameter="ButtonOne"
55 CommandTarget="{Binding ElementName=FirstStackPanel}"
56 Content="CommandTarget = FirstStackPanel" />
59 <Border BorderBrush="Black" BorderThickness="1" Margin="10"
60 Height="200" Width="200">
61 <StackPanel Background="AliceBlue" Focusable="True">
62 <Label>Second StackPanel</Label>