2016-03-07 73 views
0

我正在使用MVVM Light構建WPF應用程序。我已經添加到我的窗口中的菜單,其中包括標準文件和編輯菜單:在MVVM Light應用程序中實現編輯菜單

<Window x:Class="ParserEditor.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:local="clr-namespace:ParserEditor" 
     xmlns:ignore="http://www.galasoft.ch/ignore" 
     xmlns:i="clr namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
     xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4" 
     mc:Ignorable="d ignore" 
     Closing="Window_Closing" 
     DataContext="{Binding Main, Source={StaticResource Locator}}" 
     Height="{Binding Height, Mode=TwoWay}" 
     MaxHeight="{Binding MaxHeight, Mode=TwoWay}" 
     MinHeight="{Binding MinHeight, Mode=TwoWay}" 
     MinWidth="450" 
     Width="450" 
     Title="{Binding WindowTitle}"> 

    <Window.InputBindings> 
     <KeyBinding Command="{Binding NewParserCommand}" Gesture="CTRL+N" /> 
     <KeyBinding Command="{Binding OpenParserCommand}" Gesture="CTRL+O" /> 
     <KeyBinding Command="{Binding SaveParserCommand}" Gesture="CTRL+S" /> 
     <KeyBinding Command="{Binding SaveParserAsCommand}" Gesture="ALT+A" /> 
     <KeyBinding Command="{Binding ExitCommand}" Gesture="ALT+F4" /> 
     <KeyBinding Command="{Binding ApplicationCommands.Undo}" Gesture="CTRL+Z" /> 
     <KeyBinding Command="{Binding ApplicationCommands.Redo}" Gesture="CTRL+Y" /> 
     <KeyBinding Command="{Binding ApplicationCommands.Cut}" Gesture="CTRL+X" /> 
     <KeyBinding Command="{Binding ApplicationCommands.Copy}" Gesture="CTRL+C" /> 
     <KeyBinding Command="{Binding ApplicationCommands.Paste}" Gesture="CTRL+V" /> 
     <KeyBinding Command="{Binding ApplicationCommands.Delete}" Gesture="DEL" /> 
     <KeyBinding Command="{Binding ApplicationCommands.SelectAll}" Gesture="CTRL+A" /> 
    </Window.InputBindings> 

    <DockPanel Name="Dock"> 
     <Menu IsMainMenu="true" DockPanel.Dock="Top"> 
      <MenuItem Header="_File"> 
       <MenuItem Header="_New..." InputGestureText="Ctrl-N" Command="{Binding NewParserCommand}" /> 
       <MenuItem Header="_Open..." InputGestureText="Ctrl-O" Command="{Binding OpenParserCommand}" /> 
       <MenuItem Header="_Save..." InputGestureText="Ctrl-S" Command="{Binding SaveParserCommand}" /> 
       <MenuItem Header="Save _As..." InputGestureText="Alt-A" Command="{Binding SaveParserAsCommand}" /> 
       <Separator /> 
       <MenuItem Header="E_xit" InputGestureText="Alt-F4" Command="{Binding ExitCommand}" /> 
      </MenuItem> 
      <MenuItem Header="_Edit"> 
       <MenuItem Header="Undo" InputGestureText="Ctrl-Z" /> 
       <MenuItem Header="Redo" InputGestureText="Ctrl-Y" /> 
       <Separator/> 
       <MenuItem Header="Cut" InputGestureText="Ctrl-X" /> 
       <MenuItem Header="Copy" InputGestureText="Ctrl-C" /> 
       <MenuItem Header="Paste" InputGestureText="Ctrl-V" /> 
       <MenuItem Header="Delete" InputGestureText="Del" /> 
       <MenuItem Header="Select All" InputGestureText="Ctrl-A" /> 
      </MenuItem> 
     </Menu> 

     <Grid x:Name="LayoutRoot"> 
      <!-- Some controls, including TextBlocks & TextBoxes here -->    
     </Grid> 
    </DockPanel> 
</Window> 

現在,如果我運行應用程序,並進行一些編輯在TextBox控件之一,我可以用通常的鍵盤短剪切,複製&粘貼文本,撤消&重做動作,而焦點是控制。但是,如果我點擊我的編輯菜單,並使用我的選項之一,沒有任何反應。

如何讓我的菜單項正常工作?

回答

0

我想通了。發佈問題&查看XAML後,我發現編輯菜單項沒有綁定任何命令。我將所需的Command="ApplicationCommands.xxx"語句添加到現在編輯菜單起作用的XAML &。

相關問題