I
I
iRumba2015-08-11 12:11:57
WPF
iRumba, 2015-08-11 12:11:57

How to get the element under the mouse cursor in WPF?

in fact i even found 2 ways:
VisualTreeHelper.HitTest and Mouse.DirectlyOver, they both return the same thing (the top element under the cursor), but not exactly what I need.
I have a WrapPanel with several Labels. I want to know the index of the element under the mouse cursor
w.Children.IndexOf(element) in order to put another one (with a shift) in its place. But when I pass the top element to the function, I get -1, because the Label contains a TextBlock, and that is what is returned. And I need to get the Label. After all, I added a label to the panel in the xaml code, and not a text block.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question