简体   繁体   English

WPF最小化和最大化

[英]WPF Minimized and Maximized

I would like to have two startup options in my application, to start it maximized, and to start it minimized. 我想在我的应用程序中有两个启动选项,以使其最大化并以最小化启动。 No problem here, but I would also like them to have both checked, and in that case I would like it to start minimized, but if the user clicks the application to show it then it should be maximized (cover the whole screen). 没问题,但是我也希望他们都选中,在这种情况下,我希望它最小化,但是如果用户单击该应用程序以显示它,则应该最大化(覆盖整个屏幕)。 I thought that if I first maximized it befor minimizing it should stay that way, but thats not the case, here instead it just get minimized, and then when opened it's in the "normal" state. 我以为,如果我首先将其最大化是因为要使其最小化就应该保持这种方式,但是事实并非如此,这里只是使其最小化,然后在打开时处于“正常”状态。

if (ConfigHandler.Instance.Fullscreen)
    this.WindowState = WindowState.Maximized;
if (ConfigHandler.Instance.Minimized)
    this.WindowState = WindowState.Minimized;

It's StateChanged event you're looking for. 您正在寻找的是StateChanged事件。

    public MainWindow()
    {
        InitializeComponent();
        if (ConfigHandler.Instance.Minimized)
            WindowState = System.Windows.WindowState.Minimized;
        this.StateChanged += MainWindow_StateChanged;
    }
    void MainWindow_StateChanged(object sender, EventArgs e)
    {
        if (ConfigHandler.Instance.Fullscreen)
            WindowState = System.Windows.WindowState.Maximized;
        this.StateChanged -= MainWindow_StateChanged;//to prevent further effect
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM