Windows phone 8在网格中按用户拖放网格

本文关键字:网格 用户 拖放 Windows phone | 更新日期: 2023-09-27 18:11:50

我有一个应用程序,它有一个大的网格与堆栈面板和堆栈查看器。里面有多个网格,沿着页面向下延伸。用户是否可以拖放这些网格,使它们位于不同的位置。他们应该能够移动网格向上或向下一个网格或多个网格。是否应该在每个网格的右上角有一个按钮,当用户按住它时,他们可以在stackpanel, stackviewer中向上或向下移动网格。

谢谢你的帮助:)

Windows phone 8在网格中按用户拖放网格

尝试在网格上使用hold事件来定义要移动的对象。(您可以操纵背景颜色,以显示网格现在可以移动)。

然后使用网格的操作事件来移动控件(manipulation Delta和ManipulationCompleted)。操作会给你在X和Y域的平移。使用Y平移按指定的平移向上或向下移动对象。然后可以使用ManipulationCompleted来定义网格已经完成了移动。

    private void holdEvent(object sender, System.Windows.Input.GestureEventArgs e)
    {
        // Change the background of the exercise label
        Grid grid = (Grid)sender;
        grid.setBackground(Colors.Gray);         
        // Apply manipulation events
        grid.ManipulationDelta += new EventHandler<System.Windows.Input.ManipulationDeltaEventArgs>(GridMoving);
        grid.ManipulationCompleted += new EventHandler<ManipulationCompletedEventArgs>(GridMoved);
    }
    private void GridMoving(object sender, ManipulationDeltaEventArgs e)
    {
       // Manipulate the position of the grid here
    }
    private void ExerciseMoved(object sender, ManipulationCompletedEventArgs e)
    {
        //Change background colour back
        Grid grid = (Grid)sender;
        grid.setBackground(Colors.White); // Use the original colour here   

        // Remove the manipulation events from that specified grid, so it wont move,
        // when the user trys to move a different grid.
        grid.ManipulationDelta -= ExerciseMoving;
        grid.ManipulationCompleted -= ExerciseMoved;
    }

您可以使用Microsoft.Phone.Controls.GestureListener中的DragStartedDragCompleted事件,该事件在电话工具包中可用。

希望这个链接可以帮助你:http://www.scottlogic.com/blog/2012/06/27/a-gesture-driven-windows-phone-todo-application-part-two-drag-re-ordering.html

也看看这些:

http://www.c-sharpcorner.com/uploadfile/9f8124/drag-guesture-in-windows-phone-7/

Windows phone的拖放操作

希望有帮助!

Any ManipulationDelta Event try This code

private void Images_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
        {
            if (e.PinchManipulation != null)
            {
                ImagesRoatate.ScaleX = e.PinchManipulation.CumulativeScale;
                ImagesRoatate.ScaleY = e.PinchManipulation.CumulativeScale;
                Point OriginalCenter = e.PinchManipulation.Original.Center;
                Point NewCenter = e.PinchManipulation.Current.Center;
                ImagesRoatate.TranslateX = NewCenter.X - OriginalCenter.X;
                ImagesRoatate.TranslateY = NewCenter.Y - OriginalCenter.Y;
                ImagesRoatate.Rotation = angleBetween2Lines(e.PinchManipulation.Current, e.PinchManipulation.Original);
                e.Handled = true;
            }
            else
            {
                ImagesRoatate.TranslateX +=  e.DeltaManipulation.Translation.X;
                ImagesRoatate.TranslateY += e.DeltaManipulation.Translation.Y;
            }
            System.Diagnostics.Debug.WriteLine("Images  Actual Width :- {0},Images  Actual Height :- {1}", Images.ActualWidth, Images.ActualHeight);
        }