From de21e462e723375d149723cf178aa21fc51b2fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F?= Date: Fri, 24 Apr 2026 15:38:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=A0=8F=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9A=E6=B5=8B=E9=87=8F=E4=BF=A1=E6=81=AF=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=88=B0=E4=B8=BB=E7=95=8C=E9=9D=A2=E5=BA=95=E9=83=A8=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=A0=8F=EF=BC=8C=E7=A7=BB=E9=99=A4=E5=9B=BE=E5=83=8F?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E7=8A=B6=E6=80=81=E6=A0=8F=EF=BC=8CMainViewM?= =?UTF-8?q?odel=E6=94=B9=E4=B8=BA=E5=8D=95=E4=BE=8B=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - XplorePlane/App.xaml.cs | 2 +- XplorePlane/Views/Main/MainWindow.xaml | 2 +- XplorePlane/Views/Main/ViewportPanelView.xaml | 2 - .../Views/Main/ViewportPanelView.xaml.cs | 37 +++++++++++++------ 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index a13a714..0b8391a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,6 @@ bld/ lib/ XP.ImageProcessing/ ImageProcessing.sln -ExternalLibraries/ # 排除 Libs 目录中的 DLL 和 PDB 文件(但保留目录结构) XplorePlane/Libs/Hardware/*.dll diff --git a/XplorePlane/App.xaml.cs b/XplorePlane/App.xaml.cs index 26cb81b..a66e158 100644 --- a/XplorePlane/App.xaml.cs +++ b/XplorePlane/App.xaml.cs @@ -334,7 +334,7 @@ namespace XplorePlane // 注册视图和视图模型 containerRegistry.RegisterForNavigation(); - containerRegistry.Register(); + containerRegistry.RegisterSingleton(); containerRegistry.RegisterSingleton(); // 注册图像处理服务与视图 diff --git a/XplorePlane/Views/Main/MainWindow.xaml b/XplorePlane/Views/Main/MainWindow.xaml index 42597af..3342471 100644 --- a/XplorePlane/Views/Main/MainWindow.xaml +++ b/XplorePlane/Views/Main/MainWindow.xaml @@ -571,7 +571,7 @@ FontFamily="Microsoft YaHei UI" FontSize="11" Foreground="White" - Text="就绪" /> + Text="{Binding StatusMessage}" /> - - diff --git a/XplorePlane/Views/Main/ViewportPanelView.xaml.cs b/XplorePlane/Views/Main/ViewportPanelView.xaml.cs index 9438a2f..888c67e 100644 --- a/XplorePlane/Views/Main/ViewportPanelView.xaml.cs +++ b/XplorePlane/Views/Main/ViewportPanelView.xaml.cs @@ -15,33 +15,47 @@ namespace XplorePlane.Views { public partial class ViewportPanelView : UserControl { + private MainViewModel _mainVm; + + private void SetStatus(string msg) + { + if (_mainVm == null) + { + try { _mainVm = ContainerLocator.Current?.Resolve(); } catch { } + } + if (_mainVm != null) _mainVm.StatusMessage = msg; + } + public ViewportPanelView() { InitializeComponent(); DataContextChanged += OnDataContextChanged; - // 测量事件 → 更新状态栏 + // 测量事件 → 更新主界面状态栏 RoiCanvas.MeasureCompleted += (s, e) => { - if (e is MeasureCompletedEventArgs args && DataContext is ViewportPanelViewModel vm) + if (e is MeasureCompletedEventArgs args) { string typeLabel = args.MeasureType switch { "PointToLine" => "点线距", "Angle" => "角度", + "FillRate" => "填锡率", _ => "点点距" }; - string valueText = args.MeasureType == "Angle" - ? $"{args.Distance:F2}°" - : $"{args.Distance:F2} px"; - vm.MeasurementResult = valueText; - vm.ImageInfo = $"{typeLabel}: {valueText} | 共 {args.TotalCount} 条测量"; + string valueText = args.MeasureType switch + { + "Angle" => $"{args.Distance:F2}°", + "FillRate" => $"{args.Distance:F1}%", + _ => $"{args.Distance:F2} px" + }; + SetStatus($"{typeLabel}: {valueText} | 共 {args.TotalCount} 条测量"); } }; RoiCanvas.MeasureStatusChanged += (s, e) => { - if (e is MeasureStatusEventArgs args && DataContext is ViewportPanelViewModel vm) - vm.ImageInfo = args.Message; + if (e is MeasureStatusEventArgs args) + SetStatus(args.Message); }; // 十字辅助线:直接订阅 Prism 事件 @@ -61,6 +75,7 @@ namespace XplorePlane.Views MeasurementToolMode.PointDistance => XP.ImageProcessing.RoiControl.Models.MeasureMode.PointDistance, MeasurementToolMode.PointLineDistance => XP.ImageProcessing.RoiControl.Models.MeasureMode.PointToLine, MeasurementToolMode.Angle => XP.ImageProcessing.RoiControl.Models.MeasureMode.Angle, + MeasurementToolMode.ThroughHoleFillRate => XP.ImageProcessing.RoiControl.Models.MeasureMode.FillRate, _ => XP.ImageProcessing.RoiControl.Models.MeasureMode.None }; }, Prism.Events.ThreadOption.UIThread); @@ -91,10 +106,8 @@ namespace XplorePlane.Views { RoiCanvas.ClearMeasurements(); if (DataContext is ViewportPanelViewModel vm) - { vm.ResetMeasurementState(); - vm.ImageInfo = "已清除所有测量"; - } + SetStatus("已清除所有测量"); } private void SaveOriginalImage_Click(object sender, RoutedEventArgs e)