WPF 快捷键

来源:互联网 发布:python isdigit函数 编辑:程序博客网 时间:2024/06/01 08:26
<p><pre name="code" class="csharp"> 
前台

<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>




后台

  private void button1_Click(object sender, System.Windows.RoutedEventArgs e)        {            MessageBox.Show("sss");        }        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)        {            e.CanExecute = true;        }        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)        {            button1_Click(this, null);        }


      

0 0
原创粉丝点击