From 5fb36a75698f27975a00844189cd48d5a8e65e41 Mon Sep 17 00:00:00 2001 From: sophelper <123211521@163.com> Date: Tue, 3 Nov 2026 03:35:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(App):=20GUI=20=E5=AE=9E=E6=93=8D=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E5=90=8E=E7=9A=84=E5=85=AD=E5=A4=84=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实操跑了一遍软件,逐个修掉现场暴露的问题: - 默认页导航:CreateShell 里立刻 RequestNavigate 会静默失败(区域未注册),挪到窗口 Loaded - ComboBox:WPF 默认模板白底,深色主题下选中项看不见字,重写控件模板 - 相机下拉框:DisplayMemberPath 运行时没生效(显示 ToString()),改显式 ItemTemplate - 命令状态:Prism DelegateCommand 不会因属性变化自动重估 CanExecute, 选了相机后「开始/停止」仍灰着点不动——SelectedCamera/SelectedRecipe 里补 RaiseCanExecuteChanged - 右下角「相机未连接」是静态文字,改成绑定 ConnectionText - 手部模型默认路径与实际文件名不符(palm_detection_full_* / hand_landmark_sparse_*), 之前 ResolveModel 返回 null、手部链路静默不跑,实测耗时从 0 变为 7.8ms --- src/SopHelper.App/App.xaml.cs | 8 ++- src/SopHelper.App/Themes/Styles.xaml | 67 +++++++++++++++++++ src/SopHelper.App/VVMs/SopPage/SopPage.xaml | 12 +++- .../VVMs/SopPage/SopPageViewModel.cs | 41 ++++++++++-- 4 files changed, 118 insertions(+), 10 deletions(-) diff --git a/src/SopHelper.App/App.xaml.cs b/src/SopHelper.App/App.xaml.cs index afc1148..e3dc2a3 100644 --- a/src/SopHelper.App/App.xaml.cs +++ b/src/SopHelper.App/App.xaml.cs @@ -77,8 +77,12 @@ public partial class App var window = Container.Resolve(); - // 默认页 - navigate.Navigate("SopPage"); + // 默认页:区域要等窗口加载后才注册,CreateShell 里立刻 RequestNavigate 会静默失败 + //(实测启动后内容区是空的),必须等 Loaded;走 SelectedIndex 让侧栏同步高亮。 + window.Loaded += (_, _) => + { + if (navigate.Pages.Count > 0) navigate.SelectedIndex = 0; + }; return window; } diff --git a/src/SopHelper.App/Themes/Styles.xaml b/src/SopHelper.App/Themes/Styles.xaml index 54e9089..7062b74 100644 --- a/src/SopHelper.App/Themes/Styles.xaml +++ b/src/SopHelper.App/Themes/Styles.xaml @@ -65,6 +65,73 @@ + + + + + - + diff --git a/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs b/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs index 4ad50d6..8558d66 100644 --- a/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs +++ b/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs @@ -115,14 +115,22 @@ public class SopPageViewModel : ViewModelBase public CameraInfo? SelectedCamera { get { return _selectedCamera; } - set { SetProperty(ref _selectedCamera, value); } + set + { + if (!SetProperty(ref _selectedCamera, value)) return; + RaiseCommands(); // 实测:不刷新会导致"开始/停止"一直灰着,选了相机也点不动 + } } /// 选中配方 public string? SelectedRecipe { get { return _selectedRecipe; } - set { SetProperty(ref _selectedRecipe, value); } + set + { + if (!SetProperty(ref _selectedRecipe, value)) return; + RaiseCommands(); + } } /// 画面 @@ -164,9 +172,16 @@ public class SopPageViewModel : ViewModelBase public bool IsConnected { get { return _isConnected; } - set { SetProperty(ref _isConnected, value); } + set + { + if (!SetProperty(ref _isConnected, value)) return; + RaisePropertyChanged(nameof(ConnectionText)); + } } + /// 右下角连接文字(实测静态文字不反映状态,改成绑定) + public string ConnectionText => IsConnected ? "相机已连接" : "相机未连接"; + /// 画面像素宽(ROI 覆盖层按它缩放) public double FrameWidth { @@ -215,6 +230,21 @@ public class SopPageViewModel : ViewModelBase private bool CanStart() => SelectedCamera is not null || IsRunning; + /// + /// 刷新所有命令的可用状态。Prism 的 DelegateCommand 只在被显式 raise 时才重估 CanExecute, + /// 绑定上去的按钮不会因属性变化自动亮起来(实测:选了相机"开始/停止"仍灰着)。 + /// + private void RaiseCommands() + { + // 构造函数里 LoadRecipes() 会先设 SelectedRecipe,那时命令还没创建,必须空安全 + RefreshCamerasCommand?.RaiseCanExecuteChanged(); + StartStopCommand?.RaiseCanExecuteChanged(); + TogglePauseCommand?.RaiseCanExecuteChanged(); + ResetCommand?.RaiseCanExecuteChanged(); + ApplyRecipeCommand?.RaiseCanExecuteChanged(); + SnapshotCommand?.RaiseCanExecuteChanged(); + } + /// /// 采集线程:克隆一份交给渲染定时器,避免与相机的释放抢生命周期 /// @@ -362,8 +392,9 @@ public class SopPageViewModel : ViewModelBase YoloModelPath = ResolveModel(config.Sop.Model?.Path), YoloClasses = config.Sop.Model?.Classes ?? [], YoloInputSize = config.Sop.Model?.InputSize ?? 640, - PalmModelPath = ResolveModel("models/palm_detection_full.onnx"), - LandmarkModelPath = ResolveModel("models/hand_landmark_full.onnx"), + // 文件名必须和 models/ 下实际一致,否则 ResolveModel 返回 null、手部链路静默不跑 + PalmModelPath = ResolveModel("models/palm_detection_full_Nx3x192x192_post.onnx"), + LandmarkModelPath = ResolveModel("models/hand_landmark_sparse_Nx3x224x224.onnx"), FrameStride = Math.Max(1, config.Sop.Settings.FrameStride), };