当我单击菜单栏,然后​​按快捷键时,它起作用,但否则不起作用。是否可以设置快捷键的范围?

XAML:

<Window x:Class="NewGUI_WPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:common="clr-namespace:Common;assembly=RecentFileListLib"
    Title="Sezor" Height="Auto" Width="Auto" WindowStartupLocation="Manual" Icon="/NewGUI_WPF;component/Images/i161.ICO" WindowStyle="SingleBorderWindow" Focusable="False" ResizeMode="CanResize" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="243" d:DesignWidth="314" SizeToContent="Manual" WindowState="Maximized">

<Window.CommandBindings>
    <CommandBinding Command="Save" Executed="SaveCommand" />
    <CommandBinding Command="Open" Executed="OpenCommand" />
</Window.CommandBindings>

<Grid>
    <Menu Height="23" Name="main_menu" VerticalAlignment="Top" HorizontalAlignment="Stretch" IsMainMenu="True">
        <MenuItem Name="MI_Case" Header="Case">
            <MenuItem Header="Open" Command="Open">
                <MenuItem.Icon>
                    <Image Height="16" Width="16" Source="/NewGUI_WPF;component/Images/openHS.png" />
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Save" Name="MainMenu_File_Save" Command="Save">
                <MenuItem.Icon>
                    <Image Height="16" Width="16" Source="/NewGUI_WPF;component/Images/saveHS.png" />
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Save as" Name="MainMenu_File_SaveAs" Click="MainMenu_File_SaveAs_Click" />
            <common:RecentFileList x:Name="RecentFileList" />
            <MenuItem Header="Quit" Click="MainMenu_File_Quit_Click" />
        </MenuItem>
        <MenuItem Header="View">
            <MenuItem Header="Input File" Click="MainMenu_View_InputFile_Click" />
            <MenuItem Header="Mesh File" Click="MainMenu_View_meshFile_Click" />
            <MenuItem Name="MainMenu_View_Summary" Header="Summary" Click="MainMenu_View_summary_Click" />
        </MenuItem>
        <MenuItem Header="Define" >
            <MenuItem Header="Input File" Click="MainMenu_Define_InputFile_Click" Name="MainMenu_Define_InputFile" />
            <MenuItem Header="Mesh File" Click="MainMenu_Define_MeshFile_Click" Name="MainMenu_Define_MeshFile" />
            <MenuItem Header="Simulation File" Click="MainMenu_Define_SimulFile_Click" Name="MainMenu_Define_SimulFile" />
            <MenuItem Header="Boundaries" Click="MainMenu_Define_BC_Click" />
            <MenuItem Header="Initials" Click="MainMenu_Define_Initials_Click" />
            <MenuItem Header="Spatial Discretization" Click="MainMenu_Define_SpatDis_Click" />
            <MenuItem Header="Flow" Click="MainMenu_Define_Flow_Click" />
            <MenuItem Header="Material" Click="MainMenu_Define_Material" />
            <MenuItem Header="Algoritm" Click="MainMenu_Define_Algoritm" />
            <MenuItem Header="Gradient Reconstruction">
                <RadioButton Content="Least-Squares" Checked="Least_Squares_Checked" Name="rad_GR_LS" />
                <RadioButton Content="Green-Gauss" Click="Green_Gauss_Checked" Name="rad_GR_GG" />
            </MenuItem>
        </MenuItem>
        <MenuItem Header="Run" >
            <MenuItem Header="Simulation" Click="MainMenu_Run_Simulation_Click" />
        </MenuItem>
    </Menu>
    <Frame Height="Auto" HorizontalAlignment="Left" Margin="40,60,30,20" Name="frm_summary" VerticalAlignment="Top" Width="Auto" NavigationUIVisibility="Hidden" />
    <StatusBar Height="23" Name="statusBar1" VerticalAlignment="Bottom" Margin="0">
        <TextBlock Name="statBar_text_1"></TextBlock>
    </StatusBar>
</Grid>




码:

private void OpenCommand(object sender, ExecutedRoutedEventArgs e) {...}
private void SaveCommand(object sender, ExecutedRoutedEventArgs e) {...}

最佳答案

在您的Focusable="False"标记中删除Window

关于c# - 菜单快捷键的范围,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10095611/

10-10 09:09