From f4a0486e63d2a40c8271fd38656df65246c468be Mon Sep 17 00:00:00 2001 From: JT Date: Sun, 22 Oct 2023 21:42:06 -0700 Subject: [PATCH] didn't need global event --- .../ViewModels/CheckpointsPageViewModel.cs | 1 - .../Views/CheckpointsPage.axaml.cs | 16 ++++++++-------- StabilityMatrix.Core/Helper/EventManager.cs | 4 ---- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs index 9cc14928..86b7fdd3 100644 --- a/StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs @@ -143,7 +143,6 @@ public partial class CheckpointsPageViewModel : PageViewModelBase ) { settingsManager.Transaction(s => s.ShowConnectedModelImages = value); - EventManager.Instance.OnInvalidateRepeaterRequested(); } } diff --git a/StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs b/StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs index 82e77cc5..7bb2eb77 100644 --- a/StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs +++ b/StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs @@ -5,7 +5,9 @@ using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.VisualTree; +using DynamicData.Binding; using StabilityMatrix.Avalonia.Controls; +using StabilityMatrix.Avalonia.ViewModels; using StabilityMatrix.Core.Attributes; using StabilityMatrix.Core.Helper; using CheckpointFolder = StabilityMatrix.Avalonia.ViewModels.CheckpointManager.CheckpointFolder; @@ -34,16 +36,14 @@ public partial class CheckpointsPage : UserControlBase protected override void OnLoaded(RoutedEventArgs e) { base.OnLoaded(e); - EventManager.Instance.InvalidateRepeaterRequested += OnInvalidateRepeaterRequested; - } - - protected override void OnUnloaded(RoutedEventArgs e) - { - base.OnUnloaded(e); - EventManager.Instance.InvalidateRepeaterRequested -= OnInvalidateRepeaterRequested; + if (DataContext is CheckpointsPageViewModel vm) + { + vm.WhenPropertyChanged(v => v.ShowConnectedModelImages) + .Subscribe(_ => InvalidateRepeater()); + } } - private void OnInvalidateRepeaterRequested(object? sender, EventArgs e) + private void InvalidateRepeater() { repeater ??= this.FindControl("FilesRepeater"); repeater?.InvalidateArrange(); diff --git a/StabilityMatrix.Core/Helper/EventManager.cs b/StabilityMatrix.Core/Helper/EventManager.cs index 1bf8a2ae..72a2b3c3 100644 --- a/StabilityMatrix.Core/Helper/EventManager.cs +++ b/StabilityMatrix.Core/Helper/EventManager.cs @@ -37,7 +37,6 @@ public class EventManager public event EventHandler? ImageFileAdded; public event EventHandler? InferenceTextToImageRequested; public event EventHandler? InferenceUpscaleRequested; - public event EventHandler? InvalidateRepeaterRequested; public void OnGlobalProgressChanged(int progress) => GlobalProgressChanged?.Invoke(this, progress); @@ -84,7 +83,4 @@ public class EventManager public void OnInferenceUpscaleRequested(LocalImageFile imageFile) => InferenceUpscaleRequested?.Invoke(this, imageFile); - - public void OnInvalidateRepeaterRequested() => - InvalidateRepeaterRequested?.Invoke(this, EventArgs.Empty); }