From the course: Windows Presentation Foundation 5: Interaction and Controls

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Hit testing with geometries

Hit testing with geometries

From the course: Windows Presentation Foundation 5: Interaction and Controls

Start my 1-month free trial

Hit testing with geometries

- [Instructor] We have a requirement in our application to detect when the user has moused over these shapes. On the top, I have a polygon. On the bottom, I have a path. So, that's not hard to do in WPF because the shape class has several mouse events that would work. I've got the mouse enter, mouse leave and there's also the mouse move. So, I could wire up an event handler to list for those events and then when the user mouses over those shapes, I could run the code. The problem is, we have a further requirement to only detect when the user's over certain portions of the shape. Only when they're over the stroke. Like this. So, the mouse moves into the stroke, I detect that and change the color when I move out of the stroke, it changes back to the original value. When I move into the interior part of the shape where the fill property is, that doesn't count so I set it back to the original values. Same down here. Over the stroke it changes. Outside the stroke, it goes back to the…

Contents