2011-11-09 5 views
3

wpf 응용 프로그램에 익숙하며 응용 프로그램에서 작업 중이며 메뉴를 만들었습니다. 이제는 단축키 Ctrl + O, Ctrl + N 등에서 메뉴 항목 이벤트 기능을 원합니다. 어떻게 할 수 있습니까? 나는 그것을한다. 세부 사항을 나에게 줘라.Wpf 응용 프로그램에서 단축키 구현

+0

http://blogs.windowsclient.net/vsdev/archive/2009/03/30/wpf-menu-how-to-implement-shortcut-keys.aspx – Kendrick

+0

@Anu 어떤 프레임 워크에서 작업하고 있습니까? 닷넷 4.0 또는 닷넷 3.5 ?? – Ankesh

+0

VS2010에서 작업 중입니다 .4.0 – Anu

답변

3

할 수 있습니다 그래서 다음과 같은 방법으로 .... 파일 뒤에 코드에서 XAML 파일

<Window x:Class="FocusDemo.Window1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:FocusDemo" 
Title="Window1" Height="300" Width="300"> 

<Window.CommandBindings> 
    <CommandBinding 
     Command= 
     "{x:Static 
     local:Window1.CustomRoutedCommand}"      
     Executed="ExecutedCustomCommand" 
     CanExecute="CanExecuteCustomCommand" > 
    </CommandBinding> 
</Window.CommandBindings> 
<Window.InputBindings> 
    <KeyBinding 
     Command= 
     "{x:Static 
     local:Window1.CustomRoutedCommand}" 
     Key="S" 
     Modifiers="Control"/> 
</Window.InputBindings> 
<Grid> 
<!--Your Controls--> 
</Grid> 
</Window> 

에서

/// <summary> 
/// Interaction logic for Window1.xaml 
/// </summary> 
public partial class Window1 : Window 
{ 
    public static RoutedCommand CustomRoutedCommand = new RoutedCommand();  
    public Window1() 
    {    
     InitializeComponent();  
    } 
    #region 
    public void ExecutedCustomCommand(object sender, ExecutedRoutedEventArgs e) 
    { 
     MessageBox.Show("Ctrl+S"); 
    } 


    public void CanExecuteCustomCommand(object sender, 
     CanExecuteRoutedEventArgs e) 
    { 
     e.CanExecute = true; 
    } 
    #endregion 

} 

출처 : Click here

하세요 대답이 정확하면 잊지 마라.

0

질문에 대한 정확한 대답은 아니지만 아마도 나 같은 사람은 Alt + O, Alt + N과 같은 메뉴 항목 (명령 단추)에 키보드 바로 가기를 추가하는 방법을 찾고있을 것입니다. 이 경우 항목 이름에 바로 가기 문자 앞에 구분 기호 (_)를 넣을 수 있습니다.

관련 문제