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), };