c# - WPF - 将 F 键分配给按钮

标签 c# .net wpf

我知道“_”而不是“&”,但如何将 F1、F2... 键分配给按钮? 这是一个小应用程序,我没有使用命令,只是直接单击事件处理程序,但如果需要我可以使用命令

最佳答案

很容易... 试穿....跟我来

在 Xaml 文件中:

    <Window.Resources>
        <RoutedUICommand x:Key="cmd1"></RoutedUICommand>
    </Window.Resources>
    <Window.CommandBindings>
        <CommandBinding Command="{StaticResource cmd1}" Executed="btn_font_Click"> </CommandBinding>
    </Window.CommandBindings>
    <Window.InputBindings>
        <KeyBinding  Key="F1" Command="{StaticResource cmd1}"></KeyBinding>
    </Window.InputBindings>
    <Button  Command="{StaticResource cmd1}" Name="btn_font" Grid.Column="2" Grid.Row="1" Width="60" Height="25" Content="Enter" Click="btn_font_Click" Margin="10,2"/>

在Cs文件中:

private void btn_font_Click(object sender, RoutedEventArgs e)
    {
        Font_Chooser fc = new Font_Chooser();
        fc.ShowDialog();
    }

关于c# - WPF - 将 F 键分配给按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3386206/

相关文章:

wpf - x :Reference and ElementName? 和有什么区别

c# - 如何在 Windows 中获取可用的 COM 接口(interface)列表

c# - LinqKit 嵌套调用 "LINQ to Entities does not recognize the method ' Invoke'"

c# - 禁止触发 TextChanged 事件

c# - .NET 类库中的 HTML 编码

c# - WebSecurity.IsAuthenticated 如何检查您是否已登录?

c# - 如何执行容器ViewModel与包含的ViewModel之间的通信?

c# - NHibernate 无法编译映射

.net - 使用数据库优先的具有描述属性的 Entity Framework 5 枚举

c# - 日期格式化 WPF 数据网格