I try to maximise/restore a window through a button click. If I start my application and click the maximise button, the window moves to the top/left of the monitor it's on but does not resize to the full width/height. If I restore the window and then manually resize it by dragging a border and click the maximise button again, it maximises properly. What does the manual resize do behind the scenes that make the maximise work?
I have tried to force a resize to set the Width/Height of the Window before maximising, even calling Measure with the new size but to no avail.
The Window has the following attributes in XAML (problem also occurs with resize mode set to CanResize):
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
ResizeMode="CanResizeWithGrip"
The code to maximise/restore is simply (where Window is a Window object):
if(Window.WindowState == WindowState.Maximized)
Window.WindowState = WindowState.Normal;
else
Window.WindowState = WindowState.Maximized;
The expected behaviour is that the window maximises properly regardless if the user resized it manually first.