开发者

How to get the clicked object from a MouseLeftButtonUp event registered on a parent container?

开发者 https://www.devze.com 2023-04-01 09:19 出处:网络
I have ellipses drawn on top of a canvas, I\'ve registered a MouseLeftButtonUp on the Canvas, and I and want to get what ellipse was cli开发者_StackOverflow中文版cked using:

I have ellipses drawn on top of a canvas, I've registered a MouseLeftButtonUp on the Canvas, and I and want to get what ellipse was cli开发者_StackOverflow中文版cked using:

(Ellipse)e.Source

But e.Source is always the canvas, I also tried e.OriginalSource and also did the same thing with PreviewMouseLeftButtonUp, but still same result. Event arg is MouseButtonEventArgs. What am I doing wrong? also is there a way to check if there is a child element of a canvas at a specific point.


Use e.OriginalSource instead.


You probably want PreviewMouseLeftButtonUp, not MouseLeftButtonUp. Also, you may need to register your event using Ellipse.PreviewMouseLeftButtonUp, rather than the MouseUp event on Canvas. Something like this:

<Canvas ... Ellipse.PreviewMouseLeftButtonUp="MyHandler" />

And as H.B. mentioned, you want to use e.OriginalSource, not e.Source.

EDIT: Misread the question, editing to change to PreviewMouse*LeftButton*Up

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号