UWP:使用鼠标前进和后退按钮的WebView

时间:2017-07-03 08:19:26

标签: webview uwp mouse back forward

我正在开发一个内置WebView的UWP-App。在WebView中,我想使用鼠标的前进和后退按钮向前和向后导航。默认情况下,WebView不支持它。 (普通浏览器会这样做)

所以我找到了PointerPressed事件,在这种情况下,我可以检查指针设备是否是鼠标,指针属性是否是IsXButton1Pressed或IsXButton2Pressed。如果我在其他用户控件上实现它,它可以很好地工作。但是在WebView用户控件上,它不起作用。

我是如何在其他用户控件上实现的:

private void Page_PointerPressed(object sender, PointerRoutedEventArgs e)
{
    PointerPoint currentPoint = e.GetCurrentPoint(this);

    if(currentPoint.PointerDevice.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
    {
        PointerPointProperties pointerProperties = currentPoint.Properties;

        if(pointerProperties.IsXButton2Pressed)
        {
            if (grd_content.Children.Count == 1 && grd_content.Children[0] is Interfaces.IWebNavigation)
            {
                Interfaces.IWebNavigation iWebNav = (Interfaces.IWebNavigation)grd_content.Children[0];

                e.Handled = iWebNav.GoForward();
            }
        }
        else if(pointerProperties.IsXButton1Pressed)
        {
            if (grd_content.Children.Count == 1 && grd_content.Children[0] is Interfaces.IWebNavigation)
            {
                Interfaces.IWebNavigation iWebNav = (Interfaces.IWebNavigation)grd_content.Children[0];

                e.Handled = iWebNav.GoBackward();
            }
        }
    }
}

如何在WebView用户控件上实现鼠标前进和后退按钮?

0 个答案:

没有答案