2014-05-08 39 views

回答

-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; 
    } 
+0

感謝您的答覆。但上面的代碼似乎並沒有工作:( – shefintk

+0

我不知道爲什麼它不適合你,但它對我很好用 確保你的webview在屏幕上顯示,並且它不在任何UI後面 – nRewik

+0

很高興聽說它適用於你。不知道我在這裏錯過了什麼。我試着在xaml中只使用一個webview,就像這樣但它仍然不起作用 – shefintk

0

頭可以使用LinqToVisualTree找到網頁視圖的邊界,並獲得事件他們。

因此其他響應的代碼變爲:

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