2012-04-10 2 views
0

다음은 메뉴 항목에 대한 바로 가기를 할당하려고 한 것입니다. 메뉴 항목을 클릭하면 제대로 작동하지만 바로 가기가 작동하지 않습니다. 어떤 생각? 나를 위해 작동메뉴 항목 바로 가기

<Window.CommandBindings> 
    <CommandBinding Command="ApplicationCommands.Save" Executed="MyCommand" /> 
</Window.CommandBindings> 

<Window.InputBindings> 
    <KeyBinding Key="S" Modifiers="Control" Command="ApplicationCommands.Save"/> 
</Window.InputBindings> 

<MenuItem Header="Save" Name="MainMenu_File_Save" Command="ApplicationCommands.Save"> 
    <MenuItem.Icon> 
     <Image Height="16" Width="16" Source="/NewGUI_WPF;component/Images/saveHS.png" /> 
    </MenuItem.Icon> 
</MenuItem> 

private void MyCommand(object sender, ExecutedRoutedEventArgs e) {...} 
+0

큰 질문입니다. 그것은 이미 여기에 대답했다 http://stackoverflow.com/questions/4682915/defining-menuitem-shortcuts –

+0

그 링크를 알아. 그러나 아직도 나는 실수를 찾지 못한다. – Shibli

+0

전체 xaml 및 코드를 게시 할 수 있습니까? 나에 관해서는 모든 것이 잘 작동한다. 아마도 다른 내부에서 같은 명령을 사용했을 것입니다. –

답변

0
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 

namespace test 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 
     } 

     private void MyCommand(object sender, ExecutedRoutedEventArgs e) 
     { 
      MessageBox.Show("Test"); 
     } 
    } 
} 

<Window x:Class="test.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Window.CommandBindings> 
    <CommandBinding Command="ApplicationCommands.Save" Executed="MyCommand" /> 
    </Window.CommandBindings> 

    <Window.InputBindings> 
    <KeyBinding Key="S" Modifiers="Control" Command="ApplicationCommands.Save"/> 
    </Window.InputBindings> 

    <Grid> 
    <Menu IsMainMenu="True"> 
    <MenuItem Header="_File"> 
     <MenuItem Header="Save" Name="MainMenu_File_Save" Command="ApplicationCommands.Save" /> 
    </MenuItem> 
    </Menu> 
    </Grid> 
</Window> 

. 너에게 효과가 있니?

+0

부모 메뉴를 클릭 한 다음 바로 가기를 실행하면 작동하지만 그렇지 않은 경우 작동합니다. – Shibli

+0

샘플이 수정되었지만 여전히 작동합니다. 응용 프로그램 창이 활성화됩니까? –

+0

xaml에서 문제가 계속 발생합니까? –