added samples
[windows-sources.git] / sdk / samples / WPFSamples / Custom_RoutedCommand / csharp / window1.xaml
blobcdd1cb3165245fd557c87f730a4e44e2d6e7394a
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"
8     Focusable="True">
9   <!-- </SnippetCustomCommandMapping-->
10   <Window.CommandBindings>
11     <CommandBinding Command="{x:Static custom:Window1.ColorCmd}"
12                     Executed="ColorCmdExecuted"
13                     CanExecute="ColorCmdCanExecute"/>
14   </Window.CommandBindings>
15   <DockPanel>
16     <Menu DockPanel.Dock="Top"
17           Height="25">
18       <MenuItem Header="Commands">
19         <MenuItem Header="Color Command"
20                   Command="{x:Static custom:Window1.ColorCmd}" />
21       </MenuItem>
22     </Menu>
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.
27         <LineBreak/>
28         <LineBreak/>
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.
31         <LineBreak/>
32         <LineBreak/>
33         Since the command attached to the Button has the CommandTarget
34         set to the first StackPanel, the StackPanel does not need focus.
35         <LineBreak/>
36       </TextBlock>
37     </Border>
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"
44                     Focusable="True">
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" />
57         </StackPanel>
58       </Border>
59       <Border BorderBrush="Black" BorderThickness="1" Margin="10"
60               Height="200" Width="200">
61         <StackPanel Background="AliceBlue" Focusable="True">
62           <Label>Second StackPanel</Label>
63         </StackPanel>
64       </Border>
65     </StackPanel>
66   </DockPanel>
67 </Window>