简体   繁体   中英

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

I've searched some posts on stackoverflow and some discussion concluded as there's no way to do this as it's standard behavior of WPF modal Window.

Isn't there really a solution to minimize(control) the parent Window from a modal child Window?

Anybody who hacked or knows a roundtrip ?

Your excellent ideas will be highly appreciated always.

Thank you !

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(); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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