C#WPF)如何通过showdialog()显示子模式窗口后最小化父窗口? [英] C# WPF) how to minimize a parent window after child modal window is showed by showdialog()?

查看:766
本文介绍了C#WPF)如何通过showdialog()显示子模式窗口后最小化父窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了一些关于stackoverflow的帖子,并进行了一些讨论,得出结论,因为这是WPF模态窗口的标准行为,因此无法执行此操作.

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.

谢谢!

推荐答案

您可以通过应用程序窗口集合获取Window的引用.这是最小化MainWindow(在我的示例中为父窗口)的示例:

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.

如果要摆脱该窗口,只需使用.Hide();并向其显示agian .Show();.

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

这篇关于C#WPF)如何通过showdialog()显示子模式窗口后最小化父窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆