Minimize a window in WPF?

大城市里の小女人 提交于 2019-11-27 05:41:31

问题


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


回答1:


set WindowState = WindowState.Minimized;




回答2:


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;



回答3:


this.WindowState = WindowState.Minimized;



回答4:


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.




回答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.




回答6:


YourWindowName.WindowState = WindowState.Minimized;



回答7:


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.



来源:https://stackoverflow.com/questions/2841258/minimize-a-window-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!