操纵事件路由

时间:2012-12-10 18:51:49

标签: c# wpf pixelsense

我需要以下指导。操纵事件应该在可视树上进行路由直到处理?

我有以下内容:

Canvas canvas = new Canvas();
canvas.Width = 1920;
canvas.Height = 1200;
canvas.IsManipulationEnabled = true;
canvas.AddHandler(ManipulationStartingEvent, new EventHandler<ManipulationStartingEventArgs>(CanvasManipulationStarting), true); 

ScatterViewItem svi = new ScatterViewItem();
svi.AddHandler(ManipulationStartingEvent, new EventHandler<ManipulationStartingEventArgs>(SVIManipulationStarting), true);
svi.Content = canvas;

public void SVIManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
   //e.Handled = true; //This fires if uncommented
}

public void CanvasManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
     e.Handled = true; //This never fires regardless :( sob
}

如果我点击画布,SVIManipulationStarting会触发,但如果它被取消注释,CanVasManipulationStarting永远不会触发?

1 个答案:

答案 0 :(得分:0)

如果我理解正确的话,Canvas如果点击它就不会引发操作事件,而ScatterViewItemCanvas的容器是Canvas的容器。引发此事件,特别是如果您在Canvas操作事件处理程序中处理它。

  • 您确定要点击画布吗?添加背景颜色进行检查。如果您的Background没有IsHitTestVisible颜色,则在将true设置为Canvas
  • 之前,它将无法点击
  • 尝试操纵ScatterViewItem而不将其添加到Canvas(但是添加到其他现有容器中)。只是为了检查您在其他情况下的{{1}}行为。
相关问题