| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using System.Windows;
- using TeamAAS.Camera;
- using TeamAAS.Dialogs;
- using TeamAAS.ViewModels;
- namespace TeamAAS
- {
- public partial class MainWindow
- {
- // 【调试开关】主页右上角“ResultRegistry 监控”按钮:调试期开启;生产发布前置为 false 即可隐藏入口。
- private const bool EnableRegistryMonitorButton = true;
- // 注册表监控窗口(非模式、单实例);关闭后置空,允许再次打开
- private Views.RegistryDebugWindow _registryMonitorWindow;
- public MainWindow(MainWindowViewModel viewModel)
- {
- InitializeComponent();
- DataContext = viewModel;
- Loaded += MainWindow_Loaded;
- Closing += MainWindow_Closing;
- // 分辨率/DPI 自适应:主窗口计算全局缩放因子(1600x900 基准),所有弹窗跟随
- UiScaler.AttachMain(this);
- // 调试用:注册表监控按钮(图标经 IconKindConverter 安全解析;生产发布关掉上面的开关即隐藏)
- RegistryMonitorIcon.Kind = IconKindConverter.ToKind("BugOutline");
- RegistryMonitorButton.Visibility = EnableRegistryMonitorButton ? Visibility.Visible : Visibility.Collapsed;
- }
- private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- // 关窗前先停采集并断开所有相机,再正常退出应用。
- // 不能用 Process.Kill():那是强制终止进程,OnExit 等一切清理事件都不会执行,
- // 相机句柄会残留,导致下次启动打不开设备。
- try { CameraManager.Instance.CloseAll(); } catch { }
- Application.Current.Shutdown();
- }
- private void MainWindow_Loaded(object sender, RoutedEventArgs e)
- {
- try
- {
- (DataContext as MainWindowViewModel)?.OnLoaded();
- }
- catch (System.Exception ex)
- {
- DialogHelper.ShowError("导航初始化失败", ex);
- }
- }
- /// <summary>
- /// 右上角齿轮按钮:code-behind 显式控制主题面板开关。
- /// 不走 IsOpen="{Binding IsChecked}" 绑定——非客户区(NonClientAreaContent)中
- /// 该绑定链不可靠;点击是否到达、面板是否打开全部由代码显式驱动。
- /// </summary>
- private void SettingsToggle_Click(object sender, RoutedEventArgs e)
- {
- var isOpen = SettingsToggle.IsChecked == true;
- TeamAAS.AppLogger.Info($"SettingsToggle_Click: IsChecked={isOpen}", nameof(MainWindow));
- if (ThemePopup == null) return;
- if (isOpen)
- {
- // 显式指定 Popup 内容的 DataContext(Popup 子树的 DataContext 继承在非客户区不可靠)
- ThemePopup.DataContext = DataContext;
- ThemePopup.IsOpen = true;
- }
- else
- {
- ThemePopup.IsOpen = false;
- }
- }
- /// <summary>面板因点击外部等被关闭时,同步齿轮按钮的勾选状态,防止下次点击翻转错乱</summary>
- private void ThemePopup_Closed(object sender, System.EventArgs e)
- {
- SettingsToggle.SetCurrentValue(System.Windows.Controls.Primitives.ToggleButton.IsCheckedProperty, false);
- }
- /// <summary>
- /// 【调试】打开 ResultRegistry 监控窗口(Main / Debug 并排显示,非模式单实例,已开则前置)。
- /// 生产环境通过 EnableRegistryMonitorButton=false 隐藏入口。
- /// </summary>
- private void RegistryMonitor_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (_registryMonitorWindow != null)
- {
- _registryMonitorWindow.Activate();
- return;
- }
- _registryMonitorWindow = new Views.RegistryDebugWindow { Owner = this };
- _registryMonitorWindow.Closed += (s, args) => _registryMonitorWindow = null;
- _registryMonitorWindow.Show();
- }
- catch (System.Exception ex)
- {
- DialogHelper.ShowError("打开注册表监控失败", ex);
- }
- }
- }
- }
|