C# 根本无法让键盘加速器工作

C# 根本无法让键盘加速器工作,c#,visual-studio,uwp,uwp-xaml,C#,Visual Studio,Uwp,Uwp Xaml,我还将这个问题发布到了微软的文档中 我试图在UWP应用程序中实现访问键和键盘加速器,据我所知,这是“良好的编码实践”。下面是MainPage.xaml中的一个片段,我试图在其中实现“打开”快捷键“Ctrl+O” MainPage.xaml.cs中包含以下代码片段: /// <summary> /// Menu option to select a file /// </summary> private void menuFileOpen

我还将这个问题发布到了微软的文档中

我试图在UWP应用程序中实现访问键和键盘加速器,据我所知,这是“良好的编码实践”。下面是MainPage.xaml中的一个片段,我试图在其中实现“打开”快捷键“Ctrl+O”


MainPage.xaml.cs中包含以下代码片段:

    /// <summary>
    /// Menu option to select a file
    /// </summary>
    private void menuFileOpen(object sender, RoutedEventArgs e)
    {
        this.OpenFile();
    }

    /// <summary>
    /// Keyboard Accelerator to select a file
    /// </summary>
    private void menuFileOpen(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
    {
        this.OpenFile();
        args.Handled = true; // because the docs say to do this
    }

    /// <summary>
    /// Opens the dialog box to select a file.
    /// </summary>
    private void OpenFile()
    {
        // TODO: write the code to open the file
        throw new NotImplementedException();
    }
//
///选择文件的菜单选项
/// 
private void menuFileOpen(对象发送方,RoutedEventArgs e)
{
这个.OpenFile();
}
/// 
///选择文件的键盘加速器
/// 
private void menuFileOpen(键盘加速器发送器、键盘加速器InvokedEventArgs参数)
{
这个.OpenFile();
args.Handled=true;//因为文档要求这样做
}
/// 
///打开对话框以选择文件。
/// 
私有void OpenFile()
{
//TODO:编写代码以打开文件
抛出新的NotImplementedException();
}
出于调试目的,由于我遇到的问题,我还没有实际实现打开文件的代码。当我从菜单中选择Open时,我应该在调试器中得到“NotImplementedException”,程序应该停止

简而言之,用鼠标选择弹出菜单项会引发异常。使用访问键也会引发异常。但是,按下键盘加速器不会产生任何效果!它没有进入“调用的”方法(上面的第二个方法签名),所以我甚至不能设置断点来查看该方法是否成功…我很确定它不会成功

我所尝试的:

  • 重命名方法以赋予它们唯一的名称
  • 在XAML文件的KeyboardAccelerator标记上添加“IsEnabled”属性,并将其设置为true

非常感谢您的帮助。

我也尝试过删除“已调用”方法,希望它能进入“单击”方法,这在其他帖子以及文档中的其他地方都有暗示,但也不起作用。我仔细查看了“args”的公开属性方法的键盘加速器版本中的参数,并且,在操作加速器并尝试一些不同的事情几分钟后,我最终使键盘加速器工作并调用正确的键盘加速器方法,而不是与页面本身关联的加速器方法…但答案是无用的!为了让键盘加速器工作,需要打开带有MenuFlyoutItem的子菜单,这样我才能查看实际选择!这不可能是正确的@微软表示,这是一个已知的问题,他们正在努力解决。在我发布问题后不久。@StanleyJointeri我想我发现了你的问题,看来我们需要等到下个月发布,希望能得到修复。我同意它不起作用。它似乎也没有在VS2019中修复,但我只是基于它不在修复列表中这一事实。同样,我也没有看到更新状态表明问题也将被解决。我能想到的唯一一件事是,这不是头等大事。UWP是为跨平台型开发而设计的,这意味着键盘加速器毫无意义。不可取,因为我想做的部分跨平台工作是针对Windows10,但我们需要耐心。
    /// <summary>
    /// Menu option to select a file
    /// </summary>
    private void menuFileOpen(object sender, RoutedEventArgs e)
    {
        this.OpenFile();
    }

    /// <summary>
    /// Keyboard Accelerator to select a file
    /// </summary>
    private void menuFileOpen(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
    {
        this.OpenFile();
        args.Handled = true; // because the docs say to do this
    }

    /// <summary>
    /// Opens the dialog box to select a file.
    /// </summary>
    private void OpenFile()
    {
        // TODO: write the code to open the file
        throw new NotImplementedException();
    }