2012-12-10 29 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在此应用程序,因为具体的数据。

谢谢。

回答