From 586b0029a51102eb4e939c46e126a9aca06654ae Mon Sep 17 00:00:00 2001 From: Ionite Date: Sat, 26 Aug 2023 18:47:25 -0400 Subject: [PATCH] Image viewer fixes --- .../Controls/FrameCarousel.axaml | 1 + .../Controls/FrameCarousel.axaml.cs | 52 ++++++------------- .../Controls/ImageGalleryCard.axaml | 41 +++------------ .../InferenceTextToImageViewModel.cs | 34 ++++++------ 4 files changed, 41 insertions(+), 87 deletions(-) diff --git a/StabilityMatrix.Avalonia/Controls/FrameCarousel.axaml b/StabilityMatrix.Avalonia/Controls/FrameCarousel.axaml index 5d062a39..fe399fce 100644 --- a/StabilityMatrix.Avalonia/Controls/FrameCarousel.axaml +++ b/StabilityMatrix.Avalonia/Controls/FrameCarousel.axaml @@ -16,6 +16,7 @@ CornerRadius="{TemplateBinding CornerRadius}"> diff --git a/StabilityMatrix.Avalonia/Controls/FrameCarousel.axaml.cs b/StabilityMatrix.Avalonia/Controls/FrameCarousel.axaml.cs index 39887880..c6637b31 100644 --- a/StabilityMatrix.Avalonia/Controls/FrameCarousel.axaml.cs +++ b/StabilityMatrix.Avalonia/Controls/FrameCarousel.axaml.cs @@ -1,14 +1,10 @@ using System; using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; using System.Diagnostics.CodeAnalysis; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Controls.Templates; -using Avalonia.Interactivity; -using DynamicData.Binding; using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Media.Animation; using FluentAvalonia.UI.Navigation; @@ -67,24 +63,6 @@ public class FrameCarousel : SelectingItemsControl TransitionInfoOverride = new SuppressNavigationTransitionInfo() }; - private void ItemsView_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) - { - if (frame is null) return; - - // If current size is 0, reset the frame cache - var count = ItemCount; - if (count == 0) - { - frame.ClearValue(Frame.CacheSizeProperty); - // Setting this to false clears the page cache and stack caches - frame.IsNavigationStackEnabled = false; - } - else - { - frame.SetValue(Frame.CacheSizeProperty, count); - } - } - /// protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { @@ -95,32 +73,21 @@ public class FrameCarousel : SelectingItemsControl frame.NavigationPageFactory = new FrameNavigationFactory(SourcePageType); - ItemsView.CollectionChanged += ItemsView_CollectionChanged; - if (SelectedItem is not null) { frame.NavigateFromObject(SelectedItem, DirectionlessNavigationOptions); } } - /// - protected override void OnLoaded(RoutedEventArgs e) - { - base.OnLoaded(e); - - if (SelectedItem is not null) - { - frame!.NavigateFromObject(SelectedItem, DirectionlessNavigationOptions); - } - } - protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { base.OnPropertyChanged(change); - if (change.Property == SelectedItemProperty && frame is not null) + if (frame is null) return; + + if (change.Property == SelectedItemProperty) { - var value = change.GetNewValue(); + if (change.GetNewValue() is not { } value) return; if (SelectedIndex > previousIndex) { @@ -138,6 +105,17 @@ public class FrameCarousel : SelectingItemsControl } previousIndex = SelectedIndex; + } + else if (change.Property == ItemCountProperty) + { + // On item count change to 0, clear the frame cache + var value = change.GetNewValue(); + + if (value == 0) + { + var pageCache = frame.GetPrivateField("_pageCache"); + pageCache?.Clear(); + } } } diff --git a/StabilityMatrix.Avalonia/Controls/ImageGalleryCard.axaml b/StabilityMatrix.Avalonia/Controls/ImageGalleryCard.axaml index bf9a23ca..b6d0265c 100644 --- a/StabilityMatrix.Avalonia/Controls/ImageGalleryCard.axaml +++ b/StabilityMatrix.Avalonia/Controls/ImageGalleryCard.axaml @@ -3,8 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:StabilityMatrix.Avalonia.Controls" xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData" - xmlns:system="clr-namespace:System;assembly=System.Runtime" - xmlns:ui="using:FluentAvalonia.UI.Controls" xmlns:vmInference="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Inference" xmlns:models="clr-namespace:StabilityMatrix.Avalonia.Models" x:DataType="vmInference:ImageGalleryCardViewModel"> @@ -40,40 +38,13 @@ - - + ItemsSource="{Binding ImageSources}" />