Minimize a window in WPF?

C#WpfWindowsResizeMinimize

C# Problem Overview


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

C# Solutions


Solution 1 - C#

set WindowState = WindowState.Minimized;

Solution 2 - C#

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;

Solution 3 - C#

this.WindowState = WindowState.Minimized;

Solution 4 - C#

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.

Solution 5 - C#

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.

Solution 6 - C#

YourWindowName.WindowState = WindowState.Minimized;

Solution 7 - C#

This works just fine for me.

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

Solution 8 - C#

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionErikaView Question on Stackoverflow
Solution 1 - C#sean eView Answer on Stackoverflow
Solution 2 - C#OdedView Answer on Stackoverflow
Solution 3 - C#AmsakannaView Answer on Stackoverflow
Solution 4 - C#LumoView Answer on Stackoverflow
Solution 5 - C#Adrian TomanView Answer on Stackoverflow
Solution 6 - C#JohnnyView Answer on Stackoverflow
Solution 7 - C#Kasper JacobsenView Answer on Stackoverflow
Solution 8 - C#TomasView Answer on Stackoverflow