implementing-hit-testing
Installation
SKILL.md
WPF FrameworkElement Hit Testing
An essential pattern for receiving mouse events when rendering directly with OnRender(DrawingContext) in a class that inherits from FrameworkElement.
1. Problem Scenario
Symptoms
- Events like
MouseLeftButtonDown,MouseMovedon't fire on controls inheriting fromFrameworkElement - Nothing happens when clicking
Cause
WPF Hit Testing is performed based on rendered pixels. If nothing is drawn in OnRender() or there's no background, that area is considered "empty" and mouse events won't be delivered.