1

InputBindings に Keybindings が定義された Window があります。それらは初めて機能し、フォーム上の任意のコントロールにフォーカスを設定したときに機能します。

しかし、Messagbox が表示されているときに [OK] を押すと、ウィンドウ内のコントロールにフォーカスを設定するまでショートカット キーが機能しません。

私のInputBindings:

<Window.InputBindings>
    <KeyBinding Gesture="Ctrl+N" Command="{x:Static local:MainWindow.NewMenuCommand}" />
    <KeyBinding Gesture="Ctrl+O" Command="{x:Static local:MainWindow.OpenMenuCommand}" />
    <KeyBinding Gesture="Ctrl+S" Command="{x:Static local:MainWindow.SaveMenuCommand}" />
    <KeyBinding Gesture="Ctrl+Q" Command="{x:Static local:MainWindow.CloseMenuCommand}" />
</Window.InputBindings>

私の CommandBindings:

<Window.CommandBindings>
    <CommandBinding Command="{x:Static local:MainWindow.NewMenuCommand}" Executed="NewEntity" />
    <CommandBinding Command="{x:Static local:MainWindow.OpenMenuCommand}" Executed="OpenEntity" />
    <CommandBinding Command="{x:Static local:MainWindow.SaveMenuCommand}" Executed="SaveEntity" />
    <CommandBinding Command="{x:Static local:MainWindow.CloseMenuCommand}" Executed="CloseEntity" />
</Window.CommandBindings>
4

1 に答える 1

1

私もこの問題に直面しましたが、それはあなたのウィンドウのフォーカスと関係がありますが、実際にはこのように解決するためのハックが1つ見つかりました-

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Activated="HandleWindowActivated"
    Title="Window1" Height="300" Width="300">

そして、コードビハインドで、このようにウィンドウにフォーカスを置きます-

private void HandleWindowActivated(object sender, EventArgs e)
{
    this.Focus();
} 
于 2011-04-29T14:58:55.383 に答える