UWP 中的 Bug 还是我遗漏了什么

Bug in UWP or am I missing something

我正在启动我的第一个通用 Windows 应用程序。我想要做的第一件事是子class 主要"Page" class 导航。出于简单的目的,我只想添加一个 RightTapped 事件挂钩来显示显示的实际页面的消息...

总之,我创建了一个全新的项目。创建了一个 class MyPage

public class MyPage : Page
{
    public MyPage()
    {
        RightTapped += MyPage_RightTapped;
    }

    private async void MyPage_RightTapped(object sender, RightTappedRoutedEventArgs e)
    {
        var dialog = new MessageDialog("This page is " + GetType(), "What is my form");
        await dialog.ShowAsync();
    }
}

然后在默认主窗体上,我将 MainPage.xaml 从

更改为
<Page

<local:MyPage

在代码隐藏中,我更改了

public sealed partial class MainPage : Page

public sealed partial class MainPage

运行 表格,有效,右键单击键盘,出现消息。

现在是问题。在主页中,在 Grid 声明处,它定义了一个背景...

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

如果我去掉这个颜色(实际颜色默认是“#FFFFFFFF”)

<Grid>

RightTapped 甚至不再有效,这是唯一的变化。我放入任何其他颜色的背景,RightTapped 起作用。

任何人都可以解释这个以及为什么它在没有背景颜色的情况下失败,背景颜色与使用背景没有任何关系?

这听起来像是记录在案的行为。 UIElement.RightTapped 的文档包含一些相关提示:

For touch actions and also for interaction-specific or manipulation events that are consequences of a touch action, an element must be hit-test visible in order to be the event source and fire the event that is associated with the action. UIElement.Visibility must be Visible. Other properties of derived types also affect hit-test visibility. For more info, see Events and routed events overview.

以及来自 Events and routed events overview: Hit testing and input events 的详细信息:

There are several factors that affect hit testing, but you can determine whether a given element can fire input events by checking its IsHitTestVisible property. This property returns true only if the element meets these criteria:

  • The element's Visibility property value is Visible.
  • The element's Background or Fill property value is not null. A nullBrush value results in transparency and hit test invisibility. (To make an element transparent but also hit testable, use a Transparent brush instead of null.)

Grid's Background property (inherited from Panel) 默认为 null,使没有 Background XAML 属性的网格不可见命中测试。