gpt4 book ai didi

wpf - 使用 MVVM 使用 Caliburn Micro 关闭所有子窗口

转载 作者:行者123 更新时间:2023-12-04 15:25:27 35 4
gpt4 key购买 nike

我有一个 WPF MVVM 应用程序。我使用 WindowManager 打开并显示 View 。我的主要 shell View 模型如下,其中 SomeMethod 显示 ConsoleView

[Export(typeof(IShell))]
public sealed class ShellViewModel :
Conductor<IScreen>.Collection.OneActive, IShell, IDataErrorInfo
{
IWindowManager windowManager = null;
...
public SomeMethod()
{
...
dynamic eo = new ExpandoObject();
eo.WindowStartupLocation = WindowStartupLocation.CenterScreen;
ConsoleViewModel console = new ConsoleViewModel("Binary Table Compilation Output");
windowManager.ShowWindow(console, null, eo);
...
}
...
}

并且ConsoleViewModel

[View(typeof(ConsoleView))]
public class ConsoleViewModel : Screen
{
...
}

问题是,如果我关闭主应用程序,ConsoleView 不会关闭。问题是,当主应用程序/shell 关闭时,如何强制关闭所有子窗口?

最佳答案

您可以将事件处理程序添加到 Window.Closed event并从那里关闭所有打开的窗口:

public void MainWindowClosed(object sender, EventArgs e)
{
foreach (Window window in Application.Current.Windows)
{
window.Close();
}
}

关于wpf - 使用 MVVM 使用 Caliburn Micro 关闭所有子窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24694333/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com