-
Notifications
You must be signed in to change notification settings - Fork 336
Description
When restoring WindowState
of LayoutFloatingWindowControl externally (i.e. dragging the floating window from the top of the screen to restore instead of using the built in title bar button), the WindowState
is set again. This results in flickering of the floating window as it struggles to go from Maximized -> Normal -> Maximized -> Normal.
Steps to repro:
- Start TestApp
- Float any window
- Use title bar button to maximize
- Use title bar button to restore (observe no flicker/lag)
- Drag window using title bar to the top of screen to maximize
- Drag window using title bar from maximized state so it automatically restores
Observation
Visible flickering and lag when restoring by dragging, especially on slower computers or when there is heavy layout updating. Might be harder to spot with the demo if you are using a higher-end computer.
Issue
I have pinpointed the problem to line 183 of the OnStateChanged
override in LayoutFloatingWindowControl.cs:
WindowState = IsMaximized ? WindowState.Maximized : WindowState.Normal;
Here, I believe the issue is when WindowState
is manually set rather than IsMaximized
. When the user drags the window from a maximized state to restore, OnStateChanged
will fire with WindowState == WindowState.Normal
, but IsMaximized
is still true
.
I believe the intention was to update IsMaximized
to match WindowState
. I resolved the issue via the following changes:
lines 180-183, LayoutFloatingWindowControl.cs
if (WindowState == WindowState.Maximized)
UpdateMaximizedState(true);
else
WindowState = IsMaximized ? WindowState.Maximized : WindowState.Normal;
to:
UpdateMaximizedState(WindowState == WindowState.Maximized);
in order to ensure IsMaximized
matches WindowState
without causing multiple changes to 'WindowState'. The flickering and lag no longer happens after that.
Notes
I have not delved too deep into AvalonDock's floating window code to find out if there was a reason for needing to set WindowState
in OnStateChanged
, and have only tested the change by observing whether the flicker/lag was happening again.
Is there an intended reason for this behavior?