我有一个应用程序,它有一个带有堆栈面板和堆栈查看器的大网格。里面有沿着页面向下的多个网格。用户是否可以拖放这些网格,使它们位于不同的位置。他们应该能够将网格向上或向下移动一个网格或多个网格。每个网格的右上角是否应该有一个按钮,当用户按住该按钮时,他们可以在堆栈面板、堆栈查看器中向上或向下移动该网格。
感谢您的帮助:)
请您参考如下方法:
尝试使用网格上的保持事件来定义要移动的对象。 (您可以操纵背景颜色以显示现在可以移动网格)。
然后使用网格的操作事件来移动控件(Manipulation Delta 和 ManipulationCompleted)。 Manipulation delta 将为您提供 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;
}
