如何在Windows应用商店应用中捕捉webview的滑动手势?

时间:2014-05-08 09:07:32

标签: webview windows-store-apps

我正在构建一个Windows应用商店应用程序(8.1),我使用webview控件来加载html文件。我需要在后面的代码中捕获webview的拖动/滑动事件。我该怎么做?

2 个答案:

答案 0 :(得分:0)

Tou可以使用LinqToVisualTree查找webview的边框并为其获取事件。

所以其他响应的代码变为:

public MainPage()
{
    this.InitializeComponent();

    var border = webView.Descendants<Border>().Last() as Border;

    border.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateInertia ;
    border.ManipulationStarted += webView_ManipulationStarted;
    border.ManipulationDelta += webView_ManipulationDelta;
}

Point start;
void webView_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    if (e.IsInertial)
    {
        int threshold = 500;
        if (start.X - e.Position.X > threshold) //swipe left
        {
            e.Complete();

            //do something here
        }
    }
}
void webView_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
    start = e.Position;
}

答案 1 :(得分:-2)

试试这个

    public MainPage()
    {
        this.InitializeComponent();

        webView.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateInertia ;
        webView.ManipulationStarted += webView_ManipulationStarted;
        webView.ManipulationDelta += webView_ManipulationDelta;
    }

    Point start;
    void webView_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        if (e.IsInertial)
        {
            int threshold = 500;
            if (start.X - e.Position.X > threshold) //swipe left
            {
                e.Complete();

                //do something here
            }
        }
    }
    void webView_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
    {
        start = e.Position;
    }