2012-12-10 53 views
1

現狀:WinRT的應用,畫布主頁上。畫布上有許多孩子。當用戶在畫布上點擊並移動指針時,我正在嘗試滾動它們。一切正常,但我不知道如何模擬慣性滾動。WinRT中,C#,帆布和兒童慣性滾動

代碼:

private GestureRecognizer gr = new GestureRecognizer(); 
public MainPage() 
     { 
      this.InitializeComponent(); 


      gr.GestureSettings = GestureSettings.ManipulationTranslateInertia; 
      gr.AutoProcessInertia = true; 
     } 

我已經訂閱了一些帆布事件:

//Pressed 
private void Canvas_PointerPressed(object sender, PointerRoutedEventArgs e) 
     { 
      if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch) 
      { 


       var _ps = e.GetIntermediatePoints(cnvMain); 
       if (_ps != null && _ps.Count > 0) 
       { 
        gr.ProcessDownEvent(_ps[0]); 
        e.Handled = true; 

        Debug.WriteLine("Pressed"); 
       } 
       initialPoint = e.GetCurrentPoint(cnvMain).Position.X; 
      } 
     } 



//Released 
private void Canvas_PointerReleased(object sender, PointerRoutedEventArgs e) 
     { 
      if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch) 
      { 

       var _ps = e.GetIntermediatePoints(cnvMain); 
       if (_ps != null && _ps.Count > 0) 
       { 
        gr.ProcessUpEvent(_ps[0]); 
        e.Handled = true; 

        Debug.WriteLine("Released"); 

      } 
     } 

// Moved 
private void Canvas_PointerMoved(object sender, PointerRoutedEventArgs e) 
     { 

      if (gr.IsActive || gr.IsInertial) 
      { 

            gr.ProcessMoveEvents(e.GetIntermediatePoints(null)); 


// Here is my code for translation of children 
       e.Handled = true; 
      } 
     } 

所以,我可以轉換畫布的孩子,但沒有慣性。我如何啓用它?

不幸的是,我不能使用類似的GridView或ListView在此應用程序,因爲具體的數據。

謝謝。

回答