How to declare handler for OnPointerEntered using cppwinrt?

僤鯓⒐⒋嵵緔 提交于 2019-12-13 03:12:08

问题


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(); });

That builds and correctly calls EnteredButton. But

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

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.


回答1:


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

  • 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.


来源:https://stackoverflow.com/questions/47931777/how-to-declare-handler-for-onpointerentered-using-cppwinrt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!