C# WPF) how to minimize a parent window after child modal window is showed by 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()显示子模式窗口后最小化父窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C#WPF)如何在showdialog()显示子模式窗口后最小化父窗口?


- C#MongoDB使用Builders查找派生对象 2022-09-04
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01