2011-04-29 6 views
1

InputBindings에 키 바인딩이 정의 된 창이 있습니다. 그들은 처음으로 작업 할 때 폼의 컨트롤에 초점을 맞 춥니 다.메시지 상자가 표시된 후 바로 가기 키가 작동하지 않습니다.

그러나 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> 

답변

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(); 
} 
+1

메시지 상자의 부모/소유자를 정의하지 않는 것과 관련이 있습니다. MessageBox.Show를 사용하여 대신에 을 (내게, "저장") : 있는 MsgBox ("저장") 는이 문제를 해결 제작 –

+0

좋아, 실제로 내 경우에는 내가 구현 한 내 사용자 지정 메시지 상자 부모/자식 관계 설정도 나를 위해 작동하지 않았다. 그래서 위의 방법을 사용했습니다. –