将事件处理程序从一个Canvas复制到另一个wpf

时间:2015-08-13 11:30:26

标签: c# wpf mousemove mouseenter eventhandler

我有Canvas。稍后在我的代码中,我创建了一个新的Canvas,它将位于第一个Canvas之上,并且应该包含一些Canvas的首个属性。

我能够设置我想要的每一件事。剩下的就是将新Canvas的{​​{1}}和MouseEnter个事件注册到原始MouseMove注册到的同一个事件处理程序。

这是一种方法吗?我用Google搜索,但没找到我要找的东西。

示例:

Canvas

1 个答案:

答案 0 :(得分:-1)

您在寻找Event Bubbling

吗?
Canvas canvas1 = new Canvas();
canvas1.Width = 200;
canvas1.Height = 200;
canvas1.Background = Brushes.Black;
canvas1.MouseDown += canvas1_MouseEnter;

Canvas canvas2 = new Canvas();
canvas2.Width = 100;
canvas2.Height = 100;
canvas2.Background = Brushes.Red;            
canvas1.Children.Add(canvas2); //canvas1 events will get fired for canvas2 also