using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Threading; using HC_APTBS.ViewModels.Dialogs; namespace HC_APTBS.Views.UserControls { /// /// Shell-level snackbar that mirrors but binds to /// . Auto-dismisses three seconds after a /// successful run; a failed or cancelled run stays until the operator clicks Dismiss. /// public partial class AutoTestSnackbarView : UserControl { private DispatcherTimer? _autoHideTimer; public AutoTestSnackbarView() { InitializeComponent(); DataContextChanged += OnDataContextChanged; } private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (e.OldValue is AutoTestProgressViewModel oldVm) oldVm.PropertyChanged -= OnVmPropertyChanged; if (e.NewValue is AutoTestProgressViewModel newVm) newVm.PropertyChanged += OnVmPropertyChanged; } private void OnVmPropertyChanged(object? sender, PropertyChangedEventArgs e) { if (e.PropertyName != nameof(AutoTestProgressViewModel.IsSuccess)) return; if (DataContext is not AutoTestProgressViewModel vm) return; if (vm.IsSuccess == true) { _autoHideTimer?.Stop(); _autoHideTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(3) }; _autoHideTimer.Tick += (_, _) => { _autoHideTimer!.Stop(); if (vm.CloseCommand.CanExecute(null)) vm.CloseCommand.Execute(null); }; _autoHideTimer.Start(); } } private void OnDismissClick(object sender, RoutedEventArgs e) { if (DataContext is AutoTestProgressViewModel vm && vm.CloseCommand.CanExecute(null)) vm.CloseCommand.Execute(null); } } }