【问题标题】:Cancel ManipulationStarting event to prevent drag&drop取消操作启动事件以防止拖放
【发布时间】:2012-12-21 20:45:01
【问题描述】:

有几个事件处理操作(因此拖放):

  • 开始操作
  • 开始操作
  • ManipulationDelta
  • ManipulationInertiaStarting
  • 操作完成

在 ManipulationStarting 事件中,事件 args(类型 ManipulationStartingRoutedEventArgs)允许我将 Mode 属性设置为 ManipulationModes.None ——这是否意味着不允许操作,因此不允许拖放,这是否正确?

我问是因为我在玩官方XAML user input events sample application 时遇到了一个奇怪的行为,尤其是在场景 4(拖放)时。

只需在 Scenario4.xaml.cs 的 ManipulationStarting 事件中将 Mode 设置为 ManipulationModes.None:

void ManipulateMe_ManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e)
{
    forceManipulationsToEnd = false;
    e.Mode = ManipulationModes.None;   // <-- this is new
    e.Handled = true;
}

尽管如此,每三次拖动尝试,我都可以拖动矩形。我录制了一个视频来演示这一点:http://www.youtube.com/watch?v=psytuTailHg

这个问题不仅出现在这个示例中,也出现在我自己的应用程序中。

问题:

  • 为什么会有这种奇怪的行为?
  • 取消拖放事件的最佳方法是什么(例如,如果不满足某些条件)?

【问题讨论】:

    标签: c# drag-and-drop windows-runtime routed-events


    【解决方案1】:

    例如,在 gridview 上,您可以实现 DragItemStarting 事件,并设置 e.Cancel = true; 以防止这种行为 - 这不符合您的需求吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多