From 18e4801ed003870cb939b13a7e9c6b7a7e65104d Mon Sep 17 00:00:00 2001 From: Tung Huynh <31434093+huynhsontung@users.noreply.github.com> Date: Sun, 28 Jan 2024 15:42:39 -0800 Subject: [PATCH] fix alternate alyout not updating on in some cases (#317) --- .../Interactions/AlternatingListViewBehavior.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Screenbox/Controls/Interactions/AlternatingListViewBehavior.cs b/Screenbox/Controls/Interactions/AlternatingListViewBehavior.cs index e49ab38ee..90ae63592 100644 --- a/Screenbox/Controls/Interactions/AlternatingListViewBehavior.cs +++ b/Screenbox/Controls/Interactions/AlternatingListViewBehavior.cs @@ -54,9 +54,20 @@ protected override void OnAttached() AssociatedObject.ActualThemeChanged += OnActualThemeChanged; AssociatedObject.ContainerContentChanging += OnContainerContentChanging; - if (AssociatedObject.Items != null) + if (AssociatedObject.Items == null) return; + AssociatedObject.Items.VectorChanged += ItemsOnVectorChanged; + if (AssociatedObject.Items.Count > 0) { - AssociatedObject.Items.VectorChanged += ItemsOnVectorChanged; + // Update alternate layout on attached if there are items. + // Item containers may be cached if the list is previously loaded + // and ContainerContentChanging event is not triggered. + for (int i = 0; i < AssociatedObject.Items.Count; i++) + { + if (AssociatedObject.ContainerFromIndex(i) is SelectorItem itemContainer) + { + UpdateAlternateLayout(itemContainer, i); + } + } } }