[英]Windows phone 8 drag and drop grid in grid by user
我有一個應用程序,其中有一個帶有網格面板和堆棧查看器的大網格。 內部有多個網格,位於頁面下方。 用戶是否可以拖放這些網格,使它們位於不同的位置。 他們應該能夠向上或向下移動網格或增加網格。 每個網格的右上角都應該有一個按鈕,當用戶按下時,他們可以在堆棧面板,stackviewer中向上或向下移動該網格。
感謝您的任何幫助 :)
嘗試使用網格上的hold事件來定義要移動的對象。 (您可以操縱背景顏色以顯示網格現在可以移動了)。
然后使用網格的操縱事件來移動控件(操縱增量和操縱完成)。 操縱增量將為您提供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
的DragStarted
和DragCompleted
事件,該事件可以在Phone Toolkit中使用 。
希望此鏈接可以為您提供幫助: 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/
希望能幫助到你!
任何ManipulationDelta事件嘗試此代碼
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.