如何使用cppwinrt声明OnPointerEntered的处理程序? [英] How to declare handler for OnPointerEntered using cppwinrt?

查看:109
本文介绍了如何使用cppwinrt声明OnPointerEntered的处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在cppwinrt(尚未提供xaml)中,我有一个Button的PointerEntered事件的处理程序,它可以正常工作。但是在尝试删除此Button(显示为图像)的默认悬停行为时,似乎我可能需要处理OnPointerEntered事件-我已经看到了涉及使用xaml触发器的解决方案,这似乎与代码等效。但是OnPointerEntered具有不同的参数列表,我找不到一种可以构建它的方法。以下是成功声明PointerEntered事件句柄的方式:

In cppwinrt (xaml not yet available) I have a handler for the PointerEntered event of a Button, and it works fine. But in attempting to remove the default hover behavior of this Button, which displays as an image, it seems I may need to handle the OnPointerEntered event instead - I have seen solutions that involve using a xaml trigger and this would seem to be a code equivalent. But OnPointerEntered has a different argument list, and I can't find a way to invoke it that will build. Here is how the PointerEntered event handle is successfully declared:

button.PointerEntered([&](winrt::Windows::Foundation::IInspectable const & sender, Windows::UI::Xaml::RoutedEventArgs const & args) { EnteredButton(); });

这会生成并正确调用EnteredButton。但是

That builds and correctly calls EnteredButton. But

button.OnPointerEntered([&](winrt::Windows::UI::Xaml::Input::PointerRoutedEventArgs const & e)
{
    EnteredButton();
});

将无法生成-我尝试了多种变体后,声明错误,但不确定如何。 (使用完全限定的名称可能不是必需的,但在任何情况下似乎都不会受到损害)。可以在cppwinrt中使用OnPointerEntered,如果可以的话如何声明?我尝试使用IPointerRoutedEventArgs代替PointerRoutedEventArgs无效。或者-如果有人知道用cppwinrt创建的Button中禁用悬停效果的另一种方法,那将起作用。

will not build - I am declaring it incorrectly but am not sure how, after trying a number of variants. (Using the fully-qualified names is maybe not necessary, but seems not to hurt in either case). Can OnPointerEntered be used in cppwinrt, and how would it be declared if so? I have tried using IPointerRoutedEventArgs instead of PointerRoutedEventArgs with no effect. Or - if anyone knows a different way to disable the hover effect in a Button created with cppwinrt, that would work.

推荐答案

您不能满足你的要求回应IInspectable的评论:

You can't do what you're asking. Echoing IInspectable's comment:


  • PointerEntered是Windows :: UI :: Xaml :: UIElement上的事件。您的代码正确地声明了它的处理程序。

  • OnPointerEntered是不是事件,因此无法对其进行处理。这是一种可重写的方法,您可以为其提供自己的实现。

  • PointerEntered is an event on Windows::UI::Xaml::UIElement. Your code is correctly declaring a handler for it.
  • OnPointerEntered is not an event, so there is no way to handle it. It is an overridable method for which you can provide your own implementation.

这篇关于如何使用cppwinrt声明OnPointerEntered的处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆