问题描述
我在 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()显示子模式窗口后最小化父窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!