C# WPF) how to minimize a parent window after child modal window is showed by showdialog()?

两盒软妹~` 提交于 2019-12-02 09:40:22

You can get the reference of your Window via application window collection. This is an example of minimizing the MainWindow which is in my example the parent window:

    private void button_Click(object sender, RoutedEventArgs e)
    {
        foreach (Window win in Application.Current.Windows.OfType<MainWindow>())
        {
            var mainWin = ((MainWindow)win);
            mainWin.WindowState = mainWin.WindowState == WindowState.Minimized ? WindowState.Normal : WindowState.Minimized;
        }
    }

You can just set the window state to minimized.

If you want to get rid of the window just use .Hide(); and to show it agian .Show();.

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