WPF shortcuts

Original: WPF Shortcuts

<p><pre name="code" class="csharp"> 
 
 
Reception

<Window.Resources>

<RoutedUICommand x:Key="btnClick" Text="Button Click"/> </Window.Resources> <Window.InputBindings> <KeyBinding Gesture="Ctrl+F" Key="F" Command="{StaticResource btnClick}"/> </Window.InputBindings> <Window.CommandBindings> <CommandBinding Command="{StaticResource btnClick}" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed"/> </Window.CommandBindings> <Grid> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="105,76,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> </Grid>
 




Backstage


  
  
  1. private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
  2. {
  3. MessageBox.Show( "sss");
  4. }
  5. private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
  6. {
  7. e.CanExecute = true;
  8. }
  9. private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
  10. {
  11. button1_Click( this, null);
  12. }


      

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12075377.html