fix(App): GUI 实操验证后的六处修复
实操跑了一遍软件,逐个修掉现场暴露的问题: - 默认页导航: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
This commit is contained in:
parent
672ae20cb8
commit
5fb36a7569
@ -77,8 +77,12 @@ public partial class App
|
||||
|
||||
var window = Container.Resolve<MainWindow>();
|
||||
|
||||
// 默认页
|
||||
navigate.Navigate("SopPage");
|
||||
// 默认页:区域要等窗口加载后才注册,CreateShell 里立刻 RequestNavigate 会静默失败
|
||||
//(实测启动后内容区是空的),必须等 Loaded;走 SelectedIndex 让侧栏同步高亮。
|
||||
window.Loaded += (_, _) =>
|
||||
{
|
||||
if (navigate.Pages.Count > 0) navigate.SelectedIndex = 0;
|
||||
};
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
@ -65,6 +65,73 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- ComboBox:WPF 默认模板是白底(SystemColors.WindowBrush),深色主题下
|
||||
浅色字落在白底上等于看不见——实测"选不了相机"就是这个。整体重写。 -->
|
||||
<Style TargetType="ComboBox">
|
||||
<Setter Property="Foreground" Value="{StaticResource Fg}" />
|
||||
<Setter Property="Background" Value="{StaticResource Panel}" />
|
||||
<Setter Property="BorderBrush" Value="{StaticResource Line}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Height" Value="28" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ComboBox">
|
||||
<Grid>
|
||||
<ToggleButton Focusable="False" ClickMode="Press"
|
||||
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<ToggleButton.Template>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Border Background="{StaticResource Panel}" BorderBrush="{StaticResource Line}"
|
||||
BorderThickness="1" CornerRadius="4">
|
||||
<Path HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,8,0"
|
||||
Fill="{StaticResource FgDim}" Data="M 0 0 L 8 0 L 4 5 Z" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</ToggleButton.Template>
|
||||
</ToggleButton>
|
||||
|
||||
<ContentPresenter Margin="8,0,24,0" VerticalAlignment="Center"
|
||||
Content="{TemplateBinding SelectionBoxItem}"
|
||||
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
|
||||
IsHitTestVisible="False" />
|
||||
|
||||
<Popup AllowsTransparency="True" Placement="Bottom" Focusable="False"
|
||||
IsOpen="{TemplateBinding IsDropDownOpen}" PopupAnimation="Slide">
|
||||
<Border Background="{StaticResource Panel}" BorderBrush="{StaticResource Line}" BorderThickness="1"
|
||||
MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<ScrollViewer MaxHeight="240">
|
||||
<StackPanel IsItemsHost="True" />
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Popup>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="ComboBoxItem">
|
||||
<Setter Property="Foreground" Value="{StaticResource Fg}" />
|
||||
<Setter Property="Padding" Value="8,6" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ComboBoxItem">
|
||||
<Border x:Name="bd" Background="Transparent" Padding="{TemplateBinding Padding}">
|
||||
<ContentPresenter />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="bd" Property="Background" Value="#22FFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter TargetName="bd" Property="Background" Value="#3300B8D4" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- 左侧导航 -->
|
||||
<Style TargetType="ListBox">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
|
||||
@ -76,8 +76,14 @@
|
||||
<TextBlock Text="相机" Width="40" />
|
||||
<ComboBox Grid.Column="1" Height="26" VerticalContentAlignment="Center"
|
||||
ItemsSource="{Binding Cameras}"
|
||||
SelectedItem="{Binding SelectedCamera}"
|
||||
DisplayMemberPath="Name" />
|
||||
SelectedItem="{Binding SelectedCamera}">
|
||||
<!-- 实测 DisplayMemberPath 在运行时没生效(显示 ToString()),显式模板最稳 -->
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<Button Grid.Column="2" Content="刷新" Margin="6,0,0,0" Padding="10,4"
|
||||
Command="{Binding RefreshCamerasCommand}" />
|
||||
</Grid>
|
||||
@ -256,7 +262,7 @@
|
||||
</Style>
|
||||
</Ellipse.Style>
|
||||
</Ellipse>
|
||||
<TextBlock Text="相机未连接" Margin="6,0,0,0" Foreground="{StaticResource FgDim}" />
|
||||
<TextBlock Text="{Binding ConnectionText}" Margin="6,0,0,0" Foreground="{StaticResource FgDim}" />
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
@ -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(); // 实测:不刷新会导致"开始/停止"一直灰着,选了相机也点不动
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>选中配方</summary>
|
||||
public string? SelectedRecipe
|
||||
{
|
||||
get { return _selectedRecipe; }
|
||||
set { SetProperty(ref _selectedRecipe, value); }
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _selectedRecipe, value)) return;
|
||||
RaiseCommands();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>画面</summary>
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>右下角连接文字(实测静态文字不反映状态,改成绑定)</summary>
|
||||
public string ConnectionText => IsConnected ? "相机已连接" : "相机未连接";
|
||||
|
||||
/// <summary>画面像素宽(ROI 覆盖层按它缩放)</summary>
|
||||
public double FrameWidth
|
||||
{
|
||||
@ -215,6 +230,21 @@ public class SopPageViewModel : ViewModelBase
|
||||
|
||||
private bool CanStart() => SelectedCamera is not null || IsRunning;
|
||||
|
||||
/// <summary>
|
||||
/// 刷新所有命令的可用状态。Prism 的 DelegateCommand 只在被显式 raise 时才重估 CanExecute,
|
||||
/// 绑定上去的按钮不会因属性变化自动亮起来(实测:选了相机"开始/停止"仍灰着)。
|
||||
/// </summary>
|
||||
private void RaiseCommands()
|
||||
{
|
||||
// 构造函数里 LoadRecipes() 会先设 SelectedRecipe,那时命令还没创建,必须空安全
|
||||
RefreshCamerasCommand?.RaiseCanExecuteChanged();
|
||||
StartStopCommand?.RaiseCanExecuteChanged();
|
||||
TogglePauseCommand?.RaiseCanExecuteChanged();
|
||||
ResetCommand?.RaiseCanExecuteChanged();
|
||||
ApplyRecipeCommand?.RaiseCanExecuteChanged();
|
||||
SnapshotCommand?.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 采集线程:克隆一份交给渲染定时器,避免与相机的释放抢生命周期
|
||||
/// </summary>
|
||||
@ -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),
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user