Created
December 2, 2022 10:09
-
-
Save SchreinerK/54436a7d5cbc596bca8afabad26fc53c to your computer and use it in GitHub Desktop.
Show Window on Mouse Position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class PopupWindow : Window { | |
public PopupWindow() { | |
InitializeComponent(); | |
WindowStartupLocation = WindowStartupLocation.Manual; | |
Loaded += (s, e) => { // HACK1: use Loaded | |
Mouse.Capture(this); // HACK2: use Capture | |
var p = PointToScreen(Mouse.GetPosition(this)); | |
Mouse.Capture(null); | |
var source = PresentationSource.FromVisual(this); | |
p = new Point( // HACK2: use Transform | |
p.X / source.CompositionTarget.TransformToDevice.M11, | |
p.Y / source.CompositionTarget.TransformToDevice.M22 | |
); | |
Left = p.X - (ActualWidth / 2); | |
Top = p.Y - 16; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment