Xamarin右键单击事件

问题描述 投票:0回答:1

将Xamarin用于UWP应用时,是否有任何方法可以检测鼠标的右键单击事件?似乎没有任何方法可以访问鼠标事件,除非它们模拟触摸事件。

xamarin mouseevent right-click
1个回答
0
投票

如果这只是一个纯UWP应用,则可以订阅UIElement.PointerPressed事件。

void Target_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    Windows.UI.Xaml.Input.Pointer ptr = e.Pointer;

    if (ptr.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
    {
        Windows.UI.Input.PointerPoint ptrPt = e.GetCurrentPoint(Target);

        if (ptrPt.Properties.IsRightButtonPressed)
        {
            // Do something
        }

        // Prevent most handlers along the event route from handling the same event again.
        e.Handled = true;
    }
}

查看docs了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.