dotnet / dotnet/wpf

HitTest is buggy / not accurate when the UserControl's RenderTransform set to a large scale(ScaleX = ScaleY = 500)

Open
#7,989 12 comments 1 reaction 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

.NET 6 or higher / WPF

I have set UserControl's RenderTransform to a ScaleTransform(ScaleX = ScaleY = 500), and set the UserControl's Template to be a Line shape. However, when running the application, I noticed that the mouse events of UserControl are triggered when the mouse click or move in the blank area near the line.
When I set the scale to a smaller value,like ScaleX = ScaleY = 1, I don't encounter this issue.

I find an similar problem here(https://social.msdn.microsoft.com/Forums/vstudio/en-US/8708e340-f734-4cf4-b91d-28b49fee2b72/hittest-is-buggy-not-accurate-for-transformed-scaled-etc-visuals?forum=wpf), but it seems that it has not been fixed yet.

Click in the blank area near the line:
![1](https://github.com/dotnet/wpf/assets/54102844/f2d5a652-9d73-4871-a22b-83ed311752ab)

### Reproduction Steps

My demo code in github: https://github.com/yao-xiaofei/ShapeTest

Here is my code:

```



















```

### Expected behavior

My expectation is that when I set a larger scale value(ScaleX = ScaleY = 500 or larger), the UserControl should only respond to mouse events when clicking on the area of the line, and avoid triggering mouse events in the blank area.

![2](https://github.com/dotnet/wpf/assets/54102844/72f05918-42ad-4557-b721-d154fd1701f1)

### Actual behavior

The mouse events of UserControl are triggered when the mouse click or move in the blank area near the line.

Click in the blank area near the line:
![1](https://github.com/dotnet/wpf/assets/54102844/f2d5a652-9d73-4871-a22b-83ed311752ab)

### Regression?

_No response_

### Known Workarounds

_No response_

### Impact

_No response_

### Configuration

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.