I am creating a C# WPF application and looking for a way to do the following:
I have a canvas with different user controls in it and a button.
When I click on the button the cursor change to a hand (Canvas.Cursor = Cursors.Hand)
Then if I click on one of the controls I get a message box showing the name of the control clicked (the name is a public property of the control).
If I click somewhere else i the cursor resets and I should click on the button again before I can get the name again.
I tried playing with events and handlers but couldn't achieve what I wanted.
Thank you very much for you help
You can use
Canvas.MouseDown
and useVisualTreeHelper.HitTest()
withGetPosition()
of the mouse down event args to get the element that was clicked.Then you can use
VisualTreeHelper.GetParent()
(in awhile
loop) to get the control that was clicked.