Skip to content

Conversation

@Alessio2405
Copy link
Contributor

@Alessio2405 Alessio2405 commented Mar 4, 2025

This fix addresses an issue that occurred when detecting whether the mouse was hovering over one of the TitleBar buttons (such as minimize, maximize, or close) of a window.
The previous method of detecting the mouse position could lead to incorrect results, particularly when the pointer was moved quickly from outside to inside the window.

Pull request type

  • Update
  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes

What is the current behavior?

When creating an instance of a window with a valid parent and displaying it using ShowDialog (I can reproduce this issue only with modal windows), there's sometimes a behavior where you are unable to click any of the titlebar buttons.
The only way to resolve this issue is by first giving focus to the content of the window and then returning focus to the titlebar area, making it difficult to interact with the titlebar buttons.

Issue Number: N/A

What is the new behavior?

  • Fixed MouseOver detection: The logic for detecting mouse hover over the TitleBar buttons has been improved. The method now consistently detects the mouse position by using an interop function to ensure the accuracy of this calculation.
  • Correct transformation of coordinates: The transformation from screen coordinates to local window coordinates is now checked, even when device scaling or window transformations are in place, ensuring accurate hit testing on the TitleBar buttons.

Other information

N/A

@Alessio2405 Alessio2405 requested a review from pomianowski as a code owner March 4, 2025 16:15
@github-actions github-actions bot added controls Changes to the appearance or logic of custom controls. PR Pull request dotnet release titlebar Titlebar updates labels Mar 4, 2025
@Difegue
Copy link
Contributor

Difegue commented Mar 21, 2025

This doesn't work in the gallery on my end - The screen coordinates seem to incorrectly translate to the visual's.

@Alessio2405
Copy link
Contributor Author

Alessio2405 commented Mar 26, 2025

This doesn't work in the gallery on my end - The screen coordinates seem to incorrectly translate to the visual's.

High-dpi issue or something? If you try something like

var screenPointLogical = presentationSource.CompositionTarget.TransformFromDevice.Transform(
    new System.Windows.Point(winPoint.X, winPoint.Y));

var localPoint = this.PointFromScreen(screenPointLogical);

before translating point from screen coordinates does it work for you?

I'm gonna post a gif with the behaviour before and after, since it seemed to be ok in my tests

@pomianowski pomianowski merged commit ec3466a into lepoco:main May 24, 2025
2 checks passed
pomianowski added a commit that referenced this pull request Jun 11, 2025
…est for .NET tools (#1449)

* chore: Format code and add tools manifest

* fix: Rollback incorrect position for high DPI after #1373
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

controls Changes to the appearance or logic of custom controls. dotnet PR Pull request release titlebar Titlebar updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants