WinRT、C#、画布和儿童惯性滚动

WinRT、C#、画布和儿童惯性滚动,c#,canvas,windows-runtime,C#,Canvas,Windows Runtime,场景:WinRT应用程序,主页上的画布。画布上有许多子对象。当用户点击画布并移动指针时,我试图滚动它们。一切都很好,但我不知道如何模拟惯性滚动 守则: private GestureRecognizer gr = new GestureRecognizer(); public MainPage() { this.InitializeComponent(); gr.GestureSettings = GestureSettings

场景:WinRT应用程序,主页上的画布。画布上有许多子对象。当用户点击画布并移动指针时,我试图滚动它们。一切都很好,但我不知道如何模拟惯性滚动

守则:

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


            gr.GestureSettings = GestureSettings.ManipulationTranslateInertia;
            gr.AutoProcessInertia = true;
        }
我已经订阅了一些canvas活动:

//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之类的内容。

您应该使用with。这将为您提供足够的信息来实现惯性滚动。

另一个选项是将画布放在scrollview中,让scrollview处理手势。