[英]Canvas with shape on it - MouseUp events fire on both of them when I click shape
I have canvas with ellipse like this: 我有这样的椭圆画布:
<Canvas
Name="c1"
Background="White"
MouseUp="c1_MouseUp">
<Ellipse
Width="138"
Height="143"
Fill="Chocolate"
MouseUp="Ellipse_MouseUp">
</Ellipse>
</Canvas>
With event handlers like this: 使用这样的事件处理程序:
private void Ellipse_MouseUp(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Ellipse click");
}
private void c1_MouseUp(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Canvas click");
}
Both events fire when I click on ellipse. 点击椭圆时,两个事件都会触发。 I want only
Ellipse_MouseUp
to fire. 我只想要
Ellipse_MouseUp
。
Are there any simple methods to make it work as I want? 有没有简单的方法让它按我想要的方式工作?
Mark the one you want to process e.Handled = True; 标记要处理的人e.Handled = True; http://msdn.microsoft.com/en-us/library/system.windows.input.mousebuttoneventargs.aspx
http://msdn.microsoft.com/en-us/library/system.windows.input.mousebuttoneventargs.aspx
EDIT as an example the following should work: 编辑作为一个例子,以下应该工作:
void Ellipse_MouseUp(object sender, MouseButtonEventArgs e)
{
e.Handled = True;
MessageBox.Show("Ellipse click");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.