Dirkster99 / AvalonDock

Our own development branch of the well known WPF document docking library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flicker/Lag when restoring floating window from Maximized state

skyneps opened this issue · comments

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?

Hi, thanx for the hint. I've tested your suggested change (see above reference on this ticket) with 2 monitors etc... and could not find any problem either. I cannot tell you much about the original intention since I am neither the original author nor the previous maintainer (for versions 2.0 - 3.2).

But sine this change is now part of the commit history and the ticket linkage on GitHub we'll be able to answer the question for original intention (here is another example) as long as this project continous to live here :-)

Thanx a lot for your input, Drk