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, MouseMove don't fire on controls inheriting from FrameworkElement
  • 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.


2. Solution

2.1 Draw Transparent Background (Required)

Related skills

More from christian289/dotnet-with-claudecode

Installs
1
GitHub Stars
31
First Seen
Feb 28, 2026