Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从代码隐藏设置InputGestureText_C#_Wpf - Fatal编程技术网

C# 无法从代码隐藏设置InputGestureText

C# 无法从代码隐藏设置InputGestureText,c#,wpf,C#,Wpf,我无法从代码隐藏设置InputGestureText。 快捷键可以正常工作,但不会随菜单项一起显示键字符串 下面提到了XAML和C#代码 环境: VS2012和.NET Framework 4.5 知道我错过了什么吗 //******************** //XAML //******************** <DockPanel Grid.Row="0" Grid.ColumnSpan="2"> <Menu DockPane

我无法从代码隐藏设置InputGestureText。 快捷键可以正常工作,但不会随菜单项一起显示键字符串

下面提到了XAML和C#代码

环境: VS2012和.NET Framework 4.5

知道我错过了什么吗

//********************
//XAML
//********************
        <DockPanel Grid.Row="0" Grid.ColumnSpan="2">
            <Menu DockPanel.Dock="Top" Background="White">
                <MenuItem x:Name="mnuFile" Header="_File">
                    <MenuItem x:Name="mnuFileNew" Header="_New..." />
                    <MenuItem x:Name="mnuFileOpen" Header="_Open for Editing..." />
                    <Separator />
                    <MenuItem x:Name="mnuFileExit" Header="E_xit" />
                </MenuItem>
            </Menu>
        </DockPanel>
//********************


//********************
//Code Behind
//********************

public MainWindow()
{
    InitializeComponent();

    //File > New
    mnuFileNew.Click += mnuFileNew_Click;
    RoutedCommand cmdNewReport = new RoutedCommand();
    cmdNewReport.InputGestures.Add(new KeyGesture(Key.N, ModifierKeys.Control | ModifierKeys.Shift, "Ctrl+Shift+N"));
    CommandBindings.Add(new CommandBinding(cmdNewReport, mnuFileNew_Click));
}

void mnuFileNew_Click(object sender, RoutedEventArgs e)
{
    MessageBox.Show("New Report not implemented!", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
}
//********************
//********************
//XAML
//********************
//********************
//********************
//代码隐藏
//********************
公共主窗口()
{
初始化组件();
//文件>新建
mnuFileNew.Click+=mnuFileNew\u Click;
RoutedCommand cmdNewReport=新RoutedCommand();
cmdNewReport.inputpirates.Add(新的按键手势(Key.N,ModifierKeys.Control | ModifierKeys.Shift,“Ctrl+Shift+N”);
添加(newcommandbinding(cmdNewReport,mnuFileNew_单击));
}
void mnuFileNew_单击(对象发送方,路由目标)
{
Show(“未实现新报告!”,this.Title,MessageBoxButton.OK,MessageBoxImage.Information);
}
//********************

如果要使用代码隐藏,请尝试使用此选项显示快捷方式:

mnuFileNew.Click += mnuFileNew_Click;
RoutedCommand cmdNewReport = new RoutedCommand();

var keyGesture = new KeyGesture(Key.N, ModifierKeys.Control | ModifierKeys.Shift, "Ctrl+Shift+N");
cmdNewReport.InputGestures.Add(keyGesture);
mnuFileNew.InputGestureText = keyGesture.DisplayString;

CommandBindings.Add(new CommandBinding(cmdNewReport, mnuFileNew_Click));

如果要使用代码隐藏,请尝试使用此选项显示快捷方式:

mnuFileNew.Click += mnuFileNew_Click;
RoutedCommand cmdNewReport = new RoutedCommand();

var keyGesture = new KeyGesture(Key.N, ModifierKeys.Control | ModifierKeys.Shift, "Ctrl+Shift+N");
cmdNewReport.InputGestures.Add(keyGesture);
mnuFileNew.InputGestureText = keyGesture.DisplayString;

CommandBindings.Add(new CommandBinding(cmdNewReport, mnuFileNew_Click));