Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.81 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Is there any way to alias commands in WPF?
  2. <Grid>
  3.     <Grid.CommandBindings>
  4.         <CommandBinding Command="ApplicationCommands.Delete" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed"/>
  5.     </Grid.CommandBindings>
  6.     <DockPanel>
  7.         <Menu DockPanel.Dock="Top">
  8.             <MenuItem Header="_Edit">
  9.                 <MenuItem Header="_Delete" Command="ApplicationCommands.Delete"/>
  10.             </MenuItem>
  11.         </Menu>
  12.         <StackPanel>
  13.             <TextBox Text="Some text"/>
  14.         </StackPanel>
  15.     </DockPanel>
  16. </Grid>
  17.        
  18. private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
  19. {
  20.     e.CanExecute = true;
  21. }
  22.  
  23. private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
  24. {
  25.     EditingCommands.Delete.Execute(null, Keyboard.FocusedElement);
  26. }