Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF-为按钮分配F键_C#_.net_Wpf - Fatal编程技术网

C# WPF-为按钮分配F键

C# WPF-为按钮分配F键,c#,.net,wpf,C#,.net,Wpf,我知道u而不是&但是如何分配F1,F2。。。按钮的钥匙? 这是一个小应用程序,我不使用命令,只使用直接单击事件处理程序,但我可以在必要时使用命令在我现在正在处理的小项目中,我有: <Window.Resources> <c:CommandReference x:Key="ExitCommandReference" Command="{Binding ExitCommand}" /> <c:CommandReference x:Key="ReloadC

我知道u而不是&但是如何分配F1,F2。。。按钮的钥匙?
这是一个小应用程序,我不使用命令,只使用直接单击事件处理程序,但我可以在必要时使用命令

在我现在正在处理的小项目中,我有:

<Window.Resources>
    <c:CommandReference x:Key="ExitCommandReference" Command="{Binding ExitCommand}" />
    <c:CommandReference x:Key="ReloadCommandReference" Command="{Binding ReloadCommand}" />
</Window.Resources>
<Window.InputBindings>
    <KeyBinding Key="F4" Modifiers="Alt" Command="{StaticResource ExitCommandReference}" />
    <KeyBinding Key="F5" Command="{StaticResource ReloadCommandReference}"/>
</Window.InputBindings>

在我现在正在进行的小项目中,我有:

<Window.Resources>
    <c:CommandReference x:Key="ExitCommandReference" Command="{Binding ExitCommand}" />
    <c:CommandReference x:Key="ReloadCommandReference" Command="{Binding ReloadCommand}" />
</Window.Resources>
<Window.InputBindings>
    <KeyBinding Key="F4" Modifiers="Alt" Command="{StaticResource ExitCommandReference}" />
    <KeyBinding Key="F5" Command="{StaticResource ReloadCommandReference}"/>
</Window.InputBindings>
这很容易。。。 试试看……跟我来

在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"/>
这很容易。。。 试试看……跟我来

在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"/>

代码过多;最后,我创建了一个带有键附加属性的自定义button类,在PreviewKeyUp上,我正在搜索第一个具有正确键属性的子按钮;最后,我创建了一个带有键附加属性的自定义按钮类,在PreviewKeyUp上,我正在搜索第一个具有正确键属性的子按钮,非常简单。你应该回答更多的问题!单击按钮时,btn\u字体\u单击将执行两次。为了避免这种情况,btn\u字体\u Click不应出现在太容易的情况下。你应该回答更多的问题!单击按钮时,btn\u字体\u单击将执行两次。为了避免这种情况,btn\u字体\u Click不应出现在