From e941113da9aaa87a1d47e4b698af487a5e2bf5ff Mon Sep 17 00:00:00 2001 From: xyy <544939200@qq.com> Date: Mon, 16 Mar 2026 15:36:54 +0800 Subject: [PATCH] --- MainWindow.xaml.cs | 110 +++++++++++++++++++++++++------- MainWindow2.xaml.cs | 105 +++++++++++++++++++++--------- MainWindow3.xaml.cs | 105 +++++++++++++++++++++--------- MainWindow4.xaml.cs | 105 +++++++++++++++++++++--------- ParameterSettingsWindow.xaml.cs | 107 +++++++++++++++++++++---------- ReportWindow.xaml.cs | 105 +++++++++++++++++++++--------- ReportWindow2.xaml.cs | 105 +++++++++++++++++++++--------- ReportWindow3.xaml.cs | 106 +++++++++++++++++++++--------- ReportWindow4.xaml.cs | 106 +++++++++++++++++++++--------- 9 files changed, 681 insertions(+), 273 deletions(-) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 9978f1c..5379d5e 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -386,44 +386,106 @@ namespace 自救器呼吸器综合检验仪 private void SwitchWindow(ref T windowInstance, Func createFunc) where T : Window, new() { - // 1. 停止当前窗口的定时器(不释放资源) + // 停止当前窗口的定时器(不释放资源) _readTimer?.Stop(); - // 2. 检查资源是否可用(添加重连机制) + // 检查资源是否可用(添加重连机制) if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null) { - // 尝试重新连接 - bool reconnectSuccess = TryReconnect(); - if (!reconnectSuccess) + if (!TryReconnect()) { MessageBox.Show("TCP连接已断开,请重新连接!", "提示"); return; } } - // 3. 复用窗口实例:不存在则创建,存在则激活 - if (windowInstance == null) + // 创建一个简易的加载覆盖窗口,作为状态栏/遮罩,避免白屏 + Window overlay = null; + try { - windowInstance = createFunc(); - // 添加窗口关闭事件处理 - windowInstance.Closed += (s, args) => + overlay = new Window { - // 窗口关闭时重新启动定时器并显示当前窗口 - _readTimer?.Start(); - //this.Show(); - this.Activate(); + Owner = this, + WindowStyle = WindowStyle.None, + AllowsTransparency = true, + // 取消遮罩背景色,使用完全透明背景以避免暗色遮罩 + Background = Brushes.Transparent, + ShowInTaskbar = false, + ResizeMode = ResizeMode.NoResize, + Width = this.ActualWidth, + Height = this.ActualHeight, + Left = this.Left, + Top = this.Top, + ShowActivated = false, + Topmost = true }; - } - else - { - // 激活已存在的窗口(前置显示) - windowInstance.Activate(); - //return; - } - // 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态) - this.Hide(); - windowInstance.Show(); // 使用 Show() 而不是 ShowDialog() + // 内容:底部居中的状态文本(不遮挡背景) + var grid = new Grid(); + var tb = new TextBlock + { + Text = "正在加载,请稍候...", + Foreground = Brushes.Black, + Background = Brushes.Transparent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + Margin = new Thickness(0, 0, 0, 20), + FontSize = 16 + }; + grid.Children.Add(tb); + overlay.Content = grid; + + // 显示遮罩 + overlay.Show(); + + void ShowTargetWindow(T target) + { + // 如果目标已可见,直接激活并隐藏当前 + if (target.IsVisible) + { + target.Activate(); + this.Hide(); + overlay?.Close(); + return; + } + + target.Opacity = 0; + void OnContentRendered(object s, EventArgs e) + { + target.ContentRendered -= OnContentRendered; + var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); + target.BeginAnimation(Window.OpacityProperty, anim); + this.Hide(); + target.Activate(); + overlay?.Close(); + } + + target.ContentRendered += OnContentRendered; + target.Show(); + } + + // 创建或复用窗口实例 + if (windowInstance == null) + { + windowInstance = createFunc(); + windowInstance.Closed += (s, args) => + { + _readTimer?.Start(); + this.Activate(); + }; + + ShowTargetWindow(windowInstance); + } + else + { + ShowTargetWindow(windowInstance); + } + } + catch (Exception ex) + { + overlay?.Close(); + ShowErrorMsg($"切换窗口失败:{ex.Message}"); + } } // 添加重连方法 diff --git a/MainWindow2.xaml.cs b/MainWindow2.xaml.cs index 2697f35..264098e 100644 --- a/MainWindow2.xaml.cs +++ b/MainWindow2.xaml.cs @@ -490,43 +490,86 @@ namespace 自救器呼吸器综合检验仪 } } - void ShowTargetWindow(T target) + Window overlay = null; + try { - if (target.IsVisible) + overlay = new Window { - target.Activate(); - this.Hide(); - return; - } - - target.Opacity = 0; - void OnContentRendered(object s, EventArgs e) - { - target.ContentRendered -= OnContentRendered; - var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); - target.BeginAnimation(Window.OpacityProperty, anim); - this.Hide(); - target.Activate(); - } - - target.ContentRendered += OnContentRendered; - target.Show(); - } - - if (windowInstance == null) - { - windowInstance = createFunc(); - windowInstance.Closed += (s, args) => - { - _readTimer?.Start(); - this.Activate(); + Owner = this, + WindowStyle = WindowStyle.None, + AllowsTransparency = true, + Background = Brushes.Transparent, + ShowInTaskbar = false, + ResizeMode = ResizeMode.NoResize, + Width = this.ActualWidth, + Height = this.ActualHeight, + Left = this.Left, + Top = this.Top, + ShowActivated = false, + Topmost = true }; - ShowTargetWindow(windowInstance); + var grid = new Grid(); + var tb = new TextBlock + { + Text = "正在加载,请稍候...", + Foreground = Brushes.Black, + Background = Brushes.Transparent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + Margin = new Thickness(0, 0, 0, 20), + FontSize = 16 + }; + grid.Children.Add(tb); + overlay.Content = grid; + + overlay.Show(); + + void ShowTargetWindow(T target) + { + if (target.IsVisible) + { + target.Activate(); + this.Hide(); + overlay?.Close(); + return; + } + + target.Opacity = 0; + void OnContentRendered(object s, EventArgs e) + { + target.ContentRendered -= OnContentRendered; + var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); + target.BeginAnimation(Window.OpacityProperty, anim); + this.Hide(); + target.Activate(); + overlay?.Close(); + } + + target.ContentRendered += OnContentRendered; + target.Show(); + } + + if (windowInstance == null) + { + windowInstance = createFunc(); + windowInstance.Closed += (s, args) => + { + _readTimer?.Start(); + this.Activate(); + }; + + ShowTargetWindow(windowInstance); + } + else + { + ShowTargetWindow(windowInstance); + } } - else + catch (Exception ex) { - ShowTargetWindow(windowInstance); + overlay?.Close(); + ShowErrorMsg($"切换窗口失败:{ex.Message}"); } } // 添加重连方法 diff --git a/MainWindow3.xaml.cs b/MainWindow3.xaml.cs index d4d0d0c..aae2f42 100644 --- a/MainWindow3.xaml.cs +++ b/MainWindow3.xaml.cs @@ -463,43 +463,86 @@ namespace 自救器呼吸器综合检验仪 } } - void ShowTargetWindow(T target) + Window overlay = null; + try { - if (target.IsVisible) + overlay = new Window { - target.Activate(); - this.Hide(); - return; - } - - target.Opacity = 0; - void OnContentRendered(object s, EventArgs e) - { - target.ContentRendered -= OnContentRendered; - var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); - target.BeginAnimation(Window.OpacityProperty, anim); - this.Hide(); - target.Activate(); - } - - target.ContentRendered += OnContentRendered; - target.Show(); - } - - if (windowInstance == null) - { - windowInstance = createFunc(); - windowInstance.Closed += (s, args) => - { - _readTimer?.Start(); - this.Activate(); + Owner = this, + WindowStyle = WindowStyle.None, + AllowsTransparency = true, + Background = Brushes.Transparent, + ShowInTaskbar = false, + ResizeMode = ResizeMode.NoResize, + Width = this.ActualWidth, + Height = this.ActualHeight, + Left = this.Left, + Top = this.Top, + ShowActivated = false, + Topmost = true }; - ShowTargetWindow(windowInstance); + var grid = new Grid(); + var tb = new TextBlock + { + Text = "正在加载,请稍候...", + Foreground = Brushes.Black, + Background = Brushes.Transparent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + Margin = new Thickness(0, 0, 0, 20), + FontSize = 16 + }; + grid.Children.Add(tb); + overlay.Content = grid; + + overlay.Show(); + + void ShowTargetWindow(T target) + { + if (target.IsVisible) + { + target.Activate(); + this.Hide(); + overlay?.Close(); + return; + } + + target.Opacity = 0; + void OnContentRendered(object s, EventArgs e) + { + target.ContentRendered -= OnContentRendered; + var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); + target.BeginAnimation(Window.OpacityProperty, anim); + this.Hide(); + target.Activate(); + overlay?.Close(); + } + + target.ContentRendered += OnContentRendered; + target.Show(); + } + + if (windowInstance == null) + { + windowInstance = createFunc(); + windowInstance.Closed += (s, args) => + { + _readTimer?.Start(); + this.Activate(); + }; + + ShowTargetWindow(windowInstance); + } + else + { + ShowTargetWindow(windowInstance); + } } - else + catch (Exception ex) { - ShowTargetWindow(windowInstance); + overlay?.Close(); + ShowErrorMsg($"切换窗口失败:{ex.Message}"); } } // 添加重连方法 diff --git a/MainWindow4.xaml.cs b/MainWindow4.xaml.cs index 0bc2a4d..4ec970e 100644 --- a/MainWindow4.xaml.cs +++ b/MainWindow4.xaml.cs @@ -308,43 +308,86 @@ namespace 自救器呼吸器综合检验仪 } } - void ShowTargetWindow(T target) + Window overlay = null; + try { - if (target.IsVisible) + overlay = new Window { - target.Activate(); - this.Hide(); - return; - } - - target.Opacity = 0; - void OnContentRendered(object s, EventArgs e) - { - target.ContentRendered -= OnContentRendered; - var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); - target.BeginAnimation(Window.OpacityProperty, anim); - this.Hide(); - target.Activate(); - } - - target.ContentRendered += OnContentRendered; - target.Show(); - } - - if (windowInstance == null) - { - windowInstance = createFunc(); - windowInstance.Closed += (s, args) => - { - _readTimer?.Start(); - this.Activate(); + Owner = this, + WindowStyle = WindowStyle.None, + AllowsTransparency = true, + Background = Brushes.Transparent, + ShowInTaskbar = false, + ResizeMode = ResizeMode.NoResize, + Width = this.ActualWidth, + Height = this.ActualHeight, + Left = this.Left, + Top = this.Top, + ShowActivated = false, + Topmost = true }; - ShowTargetWindow(windowInstance); + var grid = new Grid(); + var tb = new TextBlock + { + Text = "正在加载,请稍候...", + Foreground = Brushes.Black, + Background = Brushes.Transparent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + Margin = new Thickness(0, 0, 0, 20), + FontSize = 16 + }; + grid.Children.Add(tb); + overlay.Content = grid; + + overlay.Show(); + + void ShowTargetWindow(T target) + { + if (target.IsVisible) + { + target.Activate(); + this.Hide(); + overlay?.Close(); + return; + } + + target.Opacity = 0; + void OnContentRendered(object s, EventArgs e) + { + target.ContentRendered -= OnContentRendered; + var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); + target.BeginAnimation(Window.OpacityProperty, anim); + this.Hide(); + target.Activate(); + overlay?.Close(); + } + + target.ContentRendered += OnContentRendered; + target.Show(); + } + + if (windowInstance == null) + { + windowInstance = createFunc(); + windowInstance.Closed += (s, args) => + { + _readTimer?.Start(); + this.Activate(); + }; + + ShowTargetWindow(windowInstance); + } + else + { + ShowTargetWindow(windowInstance); + } } - else + catch (Exception ex) { - ShowTargetWindow(windowInstance); + overlay?.Close(); + ShowErrorMsg($"切换窗口失败:{ex.Message}"); } } private bool TryReconnect() diff --git a/ParameterSettingsWindow.xaml.cs b/ParameterSettingsWindow.xaml.cs index 5ab145a..cc95200 100644 --- a/ParameterSettingsWindow.xaml.cs +++ b/ParameterSettingsWindow.xaml.cs @@ -131,44 +131,87 @@ namespace 自救器呼吸器综合检验仪 } } - void ShowTargetWindow(T target) + Window overlay = null; + try { - if (target.IsVisible) + overlay = new Window { - target.Activate(); - this.Hide(); - return; - } - - target.Opacity = 0; - void OnContentRendered(object s, EventArgs e) - { - target.ContentRendered -= OnContentRendered; - var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); - target.BeginAnimation(Window.OpacityProperty, anim); - this.Hide(); - target.Activate(); - } - - target.ContentRendered += OnContentRendered; - target.Show(); - } - - if (windowInstance == null) - { - windowInstance = createFunc(); - windowInstance.Closed += (s, args) => - { - _readTimer?.Start(); - this.Show(); - this.Activate(); + Owner = this, + WindowStyle = WindowStyle.None, + AllowsTransparency = true, + Background = System.Windows.Media.Brushes.Transparent, + ShowInTaskbar = false, + ResizeMode = ResizeMode.NoResize, + Width = this.ActualWidth, + Height = this.ActualHeight, + Left = this.Left, + Top = this.Top, + ShowActivated = false, + Topmost = true }; - ShowTargetWindow(windowInstance); + var grid = new Grid(); + var tb = new TextBlock + { + Text = "正在加载,请稍候...", + Foreground = System.Windows.Media.Brushes.Black, + Background = System.Windows.Media.Brushes.Transparent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + Margin = new Thickness(0, 0, 0, 20), + FontSize = 16 + }; + grid.Children.Add(tb); + overlay.Content = grid; + + overlay.Show(); + + void ShowTargetWindow(T target) + { + if (target.IsVisible) + { + target.Activate(); + this.Hide(); + overlay?.Close(); + return; + } + + target.Opacity = 0; + void OnContentRendered(object s, EventArgs e) + { + target.ContentRendered -= OnContentRendered; + var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); + target.BeginAnimation(Window.OpacityProperty, anim); + this.Hide(); + target.Activate(); + overlay?.Close(); + } + + target.ContentRendered += OnContentRendered; + target.Show(); + } + + if (windowInstance == null) + { + windowInstance = createFunc(); + windowInstance.Closed += (s, args) => + { + _readTimer?.Start(); + this.Show(); + this.Activate(); + }; + + ShowTargetWindow(windowInstance); + } + else + { + ShowTargetWindow(windowInstance); + } } - else + catch (Exception ex) { - ShowTargetWindow(windowInstance); + overlay?.Close(); + ShowErrorMsg($"切换窗口失败:{ex.Message}"); } } diff --git a/ReportWindow.xaml.cs b/ReportWindow.xaml.cs index 6ec7164..f3e1919 100644 --- a/ReportWindow.xaml.cs +++ b/ReportWindow.xaml.cs @@ -272,43 +272,86 @@ namespace 自救器呼吸器综合检验仪 } } - void ShowTargetWindow(T target) + Window overlay = null; + try { - if (target.IsVisible) + overlay = new Window { - target.Activate(); - this.Hide(); - return; - } - - target.Opacity = 0; - void OnContentRendered(object s, EventArgs e) - { - target.ContentRendered -= OnContentRendered; - var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); - target.BeginAnimation(Window.OpacityProperty, anim); - this.Hide(); - target.Activate(); - } - - target.ContentRendered += OnContentRendered; - target.Show(); - } - - if (windowInstance == null) - { - windowInstance = createFunc(); - windowInstance.Closed += (s, args) => - { - this.Show(); - this.Activate(); + Owner = this, + WindowStyle = WindowStyle.None, + AllowsTransparency = true, + Background = System.Windows.Media.Brushes.Transparent, + ShowInTaskbar = false, + ResizeMode = ResizeMode.NoResize, + Width = this.ActualWidth, + Height = this.ActualHeight, + Left = this.Left, + Top = this.Top, + ShowActivated = false, + Topmost = true }; - ShowTargetWindow(windowInstance); + var grid = new Grid(); + var tb = new TextBlock + { + Text = "正在加载,请稍候...", + Foreground = System.Windows.Media.Brushes.Black, + Background = System.Windows.Media.Brushes.Transparent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + Margin = new Thickness(0, 0, 0, 20), + FontSize = 16 + }; + grid.Children.Add(tb); + overlay.Content = grid; + + overlay.Show(); + + void ShowTargetWindow(T target) + { + if (target.IsVisible) + { + target.Activate(); + this.Hide(); + overlay?.Close(); + return; + } + + target.Opacity = 0; + void OnContentRendered(object s, EventArgs e) + { + target.ContentRendered -= OnContentRendered; + var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); + target.BeginAnimation(Window.OpacityProperty, anim); + this.Hide(); + target.Activate(); + overlay?.Close(); + } + + target.ContentRendered += OnContentRendered; + target.Show(); + } + + if (windowInstance == null) + { + windowInstance = createFunc(); + windowInstance.Closed += (s, args) => + { + this.Show(); + this.Activate(); + }; + + ShowTargetWindow(windowInstance); + } + else + { + ShowTargetWindow(windowInstance); + } } - else + catch (Exception ex) { - ShowTargetWindow(windowInstance); + overlay?.Close(); + //ShowErrorMsg($"切换窗口失败:{ex.Message}"); } } diff --git a/ReportWindow2.xaml.cs b/ReportWindow2.xaml.cs index a58752f..9821ef6 100644 --- a/ReportWindow2.xaml.cs +++ b/ReportWindow2.xaml.cs @@ -290,43 +290,86 @@ namespace 自救器呼吸器综合检验仪 } } - void ShowTargetWindow(T target) + Window overlay = null; + try { - if (target.IsVisible) + overlay = new Window { - target.Activate(); - this.Hide(); - return; - } - - target.Opacity = 0; - void OnContentRendered(object s, EventArgs e) - { - target.ContentRendered -= OnContentRendered; - var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); - target.BeginAnimation(Window.OpacityProperty, anim); - this.Hide(); - target.Activate(); - } - - target.ContentRendered += OnContentRendered; - target.Show(); - } - - if (windowInstance == null) - { - windowInstance = createFunc(); - windowInstance.Closed += (s, args) => - { - this.Show(); - this.Activate(); + Owner = this, + WindowStyle = WindowStyle.None, + AllowsTransparency = true, + Background = System.Windows.Media.Brushes.Transparent, + ShowInTaskbar = false, + ResizeMode = ResizeMode.NoResize, + Width = this.ActualWidth, + Height = this.ActualHeight, + Left = this.Left, + Top = this.Top, + ShowActivated = false, + Topmost = true }; - ShowTargetWindow(windowInstance); + var grid = new Grid(); + var tb = new TextBlock + { + Text = "正在加载,请稍候...", + Foreground = System.Windows.Media.Brushes.Black, + Background = System.Windows.Media.Brushes.Transparent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + Margin = new Thickness(0, 0, 0, 20), + FontSize = 16 + }; + grid.Children.Add(tb); + overlay.Content = grid; + + overlay.Show(); + + void ShowTargetWindow(T target) + { + if (target.IsVisible) + { + target.Activate(); + this.Hide(); + overlay?.Close(); + return; + } + + target.Opacity = 0; + void OnContentRendered(object s, EventArgs e) + { + target.ContentRendered -= OnContentRendered; + var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); + target.BeginAnimation(Window.OpacityProperty, anim); + this.Hide(); + target.Activate(); + overlay?.Close(); + } + + target.ContentRendered += OnContentRendered; + target.Show(); + } + + if (windowInstance == null) + { + windowInstance = createFunc(); + windowInstance.Closed += (s, args) => + { + this.Show(); + this.Activate(); + }; + + ShowTargetWindow(windowInstance); + } + else + { + ShowTargetWindow(windowInstance); + } } - else + catch (Exception ex) { - ShowTargetWindow(windowInstance); + overlay?.Close(); + //ShowErrorMsg($"切换窗口失败:{ex.Message}"); } } diff --git a/ReportWindow3.xaml.cs b/ReportWindow3.xaml.cs index f25af82..cc6f69b 100644 --- a/ReportWindow3.xaml.cs +++ b/ReportWindow3.xaml.cs @@ -10,6 +10,7 @@ using System.Text; using System.Windows; using System.Windows.Controls; using 自救器呼吸器综合检验仪.Data; +using System.Windows.Media; using System.Windows.Media.Animation; namespace 自救器呼吸器综合检验仪 @@ -288,43 +289,86 @@ namespace 自救器呼吸器综合检验仪 } } - void ShowTargetWindow(T target) + Window overlay = null; + try { - if (target.IsVisible) + overlay = new Window { - target.Activate(); - this.Hide(); - return; - } - - target.Opacity = 0; - void OnContentRendered(object s, EventArgs e) - { - target.ContentRendered -= OnContentRendered; - var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); - target.BeginAnimation(Window.OpacityProperty, anim); - this.Hide(); - target.Activate(); - } - - target.ContentRendered += OnContentRendered; - target.Show(); - } - - if (windowInstance == null) - { - windowInstance = createFunc(); - windowInstance.Closed += (s, args) => - { - this.Show(); - this.Activate(); + Owner = this, + WindowStyle = WindowStyle.None, + AllowsTransparency = true, + Background = System.Windows.Media.Brushes.Transparent, + ShowInTaskbar = false, + ResizeMode = ResizeMode.NoResize, + Width = this.ActualWidth, + Height = this.ActualHeight, + Left = this.Left, + Top = this.Top, + ShowActivated = false, + Topmost = true }; - ShowTargetWindow(windowInstance); + var grid = new Grid(); + var tb = new TextBlock + { + Text = "正在加载,请稍候...", + Foreground = System.Windows.Media.Brushes.Black, + Background = System.Windows.Media.Brushes.Transparent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + Margin = new Thickness(0, 0, 0, 20), + FontSize = 16 + }; + grid.Children.Add(tb); + overlay.Content = grid; + + overlay.Show(); + + void ShowTargetWindow(T target) + { + if (target.IsVisible) + { + target.Activate(); + this.Hide(); + overlay?.Close(); + return; + } + + target.Opacity = 0; + void OnContentRendered(object s, EventArgs e) + { + target.ContentRendered -= OnContentRendered; + var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); + target.BeginAnimation(Window.OpacityProperty, anim); + this.Hide(); + target.Activate(); + overlay?.Close(); + } + + target.ContentRendered += OnContentRendered; + target.Show(); + } + + if (windowInstance == null) + { + windowInstance = createFunc(); + windowInstance.Closed += (s, args) => + { + this.Show(); + this.Activate(); + }; + + ShowTargetWindow(windowInstance); + } + else + { + ShowTargetWindow(windowInstance); + } } - else + catch (Exception ex) { - ShowTargetWindow(windowInstance); + overlay?.Close(); + //ShowErrorMsg($"切换窗口失败:{ex.Message}"); } } diff --git a/ReportWindow4.xaml.cs b/ReportWindow4.xaml.cs index 37c5507..53b7b5b 100644 --- a/ReportWindow4.xaml.cs +++ b/ReportWindow4.xaml.cs @@ -10,6 +10,7 @@ using System.Text; using System.Windows; using System.Windows.Controls; using 自救器呼吸器综合检验仪.Data; +using System.Windows.Media; using System.Windows.Media.Animation; namespace 自救器呼吸器综合检验仪 @@ -329,43 +330,86 @@ namespace 自救器呼吸器综合检验仪 } } - void ShowTargetWindow(T target) + Window overlay = null; + try { - if (target.IsVisible) + overlay = new Window { - target.Activate(); - this.Hide(); - return; - } - - target.Opacity = 0; - void OnContentRendered(object s, EventArgs e) - { - target.ContentRendered -= OnContentRendered; - var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); - target.BeginAnimation(Window.OpacityProperty, anim); - this.Hide(); - target.Activate(); - } - - target.ContentRendered += OnContentRendered; - target.Show(); - } - - if (windowInstance == null) - { - windowInstance = createFunc(); - windowInstance.Closed += (s, args) => - { - this.Show(); - this.Activate(); + Owner = this, + WindowStyle = WindowStyle.None, + AllowsTransparency = true, + Background = System.Windows.Media.Brushes.Transparent, + ShowInTaskbar = false, + ResizeMode = ResizeMode.NoResize, + Width = this.ActualWidth, + Height = this.ActualHeight, + Left = this.Left, + Top = this.Top, + ShowActivated = false, + Topmost = true }; - ShowTargetWindow(windowInstance); + var grid = new Grid(); + var tb = new TextBlock + { + Text = "正在加载,请稍候...", + Foreground = System.Windows.Media.Brushes.Black, + Background = System.Windows.Media.Brushes.Transparent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + Margin = new Thickness(0, 0, 0, 20), + FontSize = 16 + }; + grid.Children.Add(tb); + overlay.Content = grid; + + overlay.Show(); + + void ShowTargetWindow(T target) + { + if (target.IsVisible) + { + target.Activate(); + this.Hide(); + overlay?.Close(); + return; + } + + target.Opacity = 0; + void OnContentRendered(object s, EventArgs e) + { + target.ContentRendered -= OnContentRendered; + var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200)); + target.BeginAnimation(Window.OpacityProperty, anim); + this.Hide(); + target.Activate(); + overlay?.Close(); + } + + target.ContentRendered += OnContentRendered; + target.Show(); + } + + if (windowInstance == null) + { + windowInstance = createFunc(); + windowInstance.Closed += (s, args) => + { + this.Show(); + this.Activate(); + }; + + ShowTargetWindow(windowInstance); + } + else + { + ShowTargetWindow(windowInstance); + } } - else + catch (Exception ex) { - ShowTargetWindow(windowInstance); + overlay?.Close(); + MessageBox.Show($"切换窗口失败:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error); } }