Avalonia
Avalonia copied to clipboard
In WindowBase.PositionChanged event handler Point value is wrong
Describe the bug
The value of PixelPointEvenArgs.Point
inside event handler is wrong.
To Reproduce
Steps to reproduce the behavior:
- Create new Avalonia C# project.
- In
MainWindow.axaml.cs
add line in constructor to output argument value and actual value:
public MainWindow()
{
InitializeComponent();
PositionChanged += (s, e) => Debug.WriteLine($"Position={e.Point}, actual={Position}");
//Position = new(666, 666); // optional
}
- Run and observe debugger "Output" window.
- My outputs are
Position=190, 213, actual=188, 182
or
Position=668, 697, actual=666, 666
Expected behavior
I expect e.Point
value to be equal to actual window Position
.
Environment
- OS: Windows 11
- Avalonia-Version: 11.0.9
Additional context
I tried to use PositionChanged
event to store position of window in normal state, see #14517 ,but unfortunately discovered a new frustrating bug in Avalonia.
Looks like Position
is considered the position of the client area in some places, and the position of the window frame in others.
Maximising the window reveals that e.Point
is the location of the client area, but Position
is the location of the whole window including its frame.
Position=0, 23, actual=-1, -8
The raw value that comes from GetWindowRect is -8, -8
. An attempt is being made to counteract the window's drop shadow, but it doesn't seem to be working very well.
What should the Position
property really represent? The client area? The window frame? (I think we can discard the option of the window frame including drop shadow.)
cc @emmauss