63

How do you minimize a window programmatically when using windows WPF? I can seem to find a .Resize attribute?

Nate Zaugg
  • 4,202
  • 2
  • 36
  • 53
Erika
  • 2,045
  • 7
  • 25
  • 31

8 Answers8

130

set WindowState = WindowState.Minimized;

sean e
  • 11,792
  • 3
  • 44
  • 56
26

You are looking for the Window.WindowState property. It is a dependancy property and when changed will set the Window.RestoreBounds property , so you can always restore to the size before the change.

See the enumeration here.

myWindow.WindowState = WindowState.Minimized;
Oded
  • 489,969
  • 99
  • 883
  • 1,009
21
this.WindowState = WindowState.Minimized;
Amsakanna
  • 12,254
  • 8
  • 46
  • 58
20

For those who had the same problem: keep in mind that if ShowInTaskbar is set to false, then WindowState.Minimized minimizes the Window into a small window title bar at the bottom left of the desktop - so it's not really minimized.

A workaround is to set ShowInTaskbar to true, set WindowState to Minimized and then reset the ShowInTaskbar to its old value.

Lumo
  • 627
  • 6
  • 21
  • This helped a lot! It is actually even better to switch the `ShowInTaskbar` from true to false whenever the `WindowState` changes to `WindowState.Minimized`. That way, when the user clicks the minimize button of the window it will also vanish completely and when the window is shown it appears in the taskbar which is probably what users expect. – henon Jan 18 '23 at 11:00
5

Use the window's object WindowState property to programmaticly minimise a window.

window.WindowState = WindowState.Minimized;

Setting window state to WindowState.Normal will restore the window to it's previous WindowsState, size and location.

window.WindowState = WindowState.Normal;

Window.Normal is a bit of a misnomer. The remarks in the WindowState property and the WindowState Enumeration MSDN articles hint at WindowState.Normal actual functionality and testing confirms it.

Adrian Toman
  • 11,316
  • 5
  • 48
  • 62
4

This works just fine for me.

Application.Current.Windows[0].WindowState = WindowState.Minimized;

2
YourWindowName.WindowState = WindowState.Minimized;
Johnny
  • 1,555
  • 3
  • 14
  • 23
0

As many said,

window.WindowState = WindowState.Minimized

will minimize the window for you. But be careful about timing - I accidentally set this in a MouseLeftButtonDown handler (vs MouseLeftButtonUp), and the window would not restore.

user353gre3
  • 2,747
  • 4
  • 24
  • 27
Tomas
  • 125
  • 1
  • 10