gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 21:46:45 24 4
gpt4 key购买 nike

我要开始我的第一个通用 Windows 应用程序。我想要的第一件事是将主要的“页面”类子类化以进行导航。出于简单的目的,我只想添加一个 RightTapped 事件 Hook 来显示显示的实际页面的消息...

无论如何,我创建了一个全新的项目。创建了单个类 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.)

GridBackground property (继承自 Panel)默认为 null,使没有 Background XAML 属性的网格对 HitTest 不可见。

关于c# - UWP 中的 Bug 还是我遗漏了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39024216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com