更新
This commit is contained in:
@@ -238,22 +238,22 @@ namespace 自救器呼吸器综合检验仪
|
||||
|
||||
private void Button_Click_4(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SwitchWindow(ref _mainWindow, () => new MainWindow());
|
||||
SwitchWindow(ref _mainWindow, () => new MainWindow(), "正在进入定量供应检验", "正在准备定量供应检验页面...");
|
||||
}
|
||||
|
||||
private void Button_Click_5(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SwitchWindow(ref _mainWindow2, () => new MainWindow2());
|
||||
SwitchWindow(ref _mainWindow2, () => new MainWindow2(), "正在进入负压气密性检验", "正在切换到负压气密性检验页面...");
|
||||
}
|
||||
|
||||
private void Button_Click_6(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SwitchWindow(ref _mainWindow3, () => new MainWindow3());
|
||||
SwitchWindow(ref _mainWindow3, () => new MainWindow3(), "正在进入正压气密性检验", "正在切换到正压气密性检验页面...");
|
||||
}
|
||||
|
||||
private void Button_Click_7(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SwitchWindow(ref _mainWindow4, () => new MainWindow4());
|
||||
SwitchWindow(ref _mainWindow4, () => new MainWindow4(), "正在进入排气阀压力测试", "正在切换到排气阀压力测试页面...");
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
@@ -294,7 +294,7 @@ namespace 自救器呼吸器综合检验仪
|
||||
}
|
||||
|
||||
|
||||
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : Window, new()
|
||||
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc, string loadingTitle = null, string loadingSubtitle = null) where T : Window, new()
|
||||
{
|
||||
// 1. 停止当前窗口的定时器(不释放资源)
|
||||
_readTimer?.Stop();
|
||||
@@ -318,22 +318,12 @@ namespace 自救器呼吸器综合检验仪
|
||||
// 添加窗口关闭事件处理
|
||||
windowInstance.Closed += (s, args) =>
|
||||
{
|
||||
// 窗口关闭时重新启动定时器并显示当前窗口
|
||||
_readTimer?.Start();
|
||||
//this.Show();
|
||||
this.Activate();
|
||||
WindowNavigationHelper.RestoreWindow(this, () => _readTimer?.Start());
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活已存在的窗口(前置显示)
|
||||
windowInstance.Activate();
|
||||
//return;
|
||||
}
|
||||
|
||||
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
|
||||
this.Hide();
|
||||
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
|
||||
// 4. 目标窗口完成首帧渲染后再切换,避免白屏
|
||||
WindowNavigationHelper.ShowWithoutWhiteFlash(this, windowInstance, loadingTitle, loadingSubtitle);
|
||||
}
|
||||
private bool TryReconnect()
|
||||
{
|
||||
@@ -505,17 +495,12 @@ namespace 自救器呼吸器综合检验仪
|
||||
// 释放Modbus资源
|
||||
ModbusResourceManager.Instance?.Dispose();
|
||||
|
||||
// 确保应用程序完全退出
|
||||
Application.Current.Shutdown();
|
||||
// 延后到当前窗口完成关闭后再统一关停,避免关闭重入。
|
||||
AppShutdownCoordinator.RequestShutdown();
|
||||
}
|
||||
private void Window_Closed(object sender, EventArgs e)
|
||||
{
|
||||
// 清理其他窗口实例
|
||||
_mainWindow2?.Close();
|
||||
_mainWindow3?.Close();
|
||||
//_mainWindow4?.Close();
|
||||
_mainWindow?.Close();
|
||||
_reportWindow4?.Close();
|
||||
// 由应用级关停统一处理其他窗口,避免关闭链路重入。
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user