0

我需要以下指导。操作事件应该在视觉树上向上路由直到被处理?

我有以下内容:

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 永远不会触发?

4

1 回答 1

0

没有办法,如果我理解正确,Canvas如果你点击它就不会引发操作事件,并且ScatterViewItem(它是 的容器Canvas)引发了这个事件,特别是如果你在Canvas操作事件处理程序中处理它。

  • 你确定你在点击画布吗?添加背景颜色以检查它。如果您Canvas没有颜色,则在您设置为Background之前无法点击IsHitTestVisibletrue
  • 尝试在Canvas不将其添加到您的ScatterViewItem(但添加到其他现有容器)的情况下操作您的。只是为了检查您Canvas在其他情况下的行为。
于 2012-12-11T08:41:37.900 回答