C#WPF)如何在showdialog()显示子模式窗口后最小化父窗口?

C# WPF) how to minimize a parent window after child modal window is showed by showdialog()?(C#WPF)如何在showdialog()显示子模式窗口后最小化父窗口?)
本文介绍了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.

谢谢!

推荐答案

您可以通过应用程序窗口集合获取您的窗口的引用.这是最小化 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(); 并再次显示 .Show();.

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)