From c7a7b437268aa27e7f161e5de5e50d3f1491dc68 Mon Sep 17 00:00:00 2001 From: Prathamesh Narkhede Date: Wed, 24 Jul 2024 18:09:25 -0700 Subject: [PATCH 1/2] Optimize BasemapGallery initialization Removed redundant initialization of `AvailableBasemaps` in the `BasemapGallery` constructor. Added a null check in `BasemapGallery_Loaded` to initialize `AvailableBasemaps` only if it is null, calling `_controller.LoadFromDefaultPortal()` asynchronously if needed. This change prevents unnecessary initialization and allows for external setting of `AvailableBasemaps` before the control is loaded. --- .../BasemapGallery/BasemapGallery.Windows.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs b/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs index 66ecfb5f8..6695a7f2d 100644 --- a/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs +++ b/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs @@ -43,7 +43,6 @@ public BasemapGallery() _controller = new BasemapGalleryController(); DefaultStyleKey = typeof(BasemapGallery); SizeChanged += BasemapGallerySizeChanged; - AvailableBasemaps = new ObservableCollection(); _controller.PropertyChanged += HandleControllerPropertyChanged; Loaded += BasemapGallery_Loaded; } @@ -52,7 +51,7 @@ private async void BasemapGallery_Loaded(object? sender, RoutedEventArgs e) { // Unsubscribe from the Loaded event to ensure this only runs once. Loaded -= BasemapGallery_Loaded; - + if (AvailableBasemaps is null) { await _controller.LoadFromDefaultPortal(); From 89d292aae9dfe91120c747aed4a987f16f7f8da6 Mon Sep 17 00:00:00 2001 From: Prathamesh Narkhede Date: Thu, 25 Jul 2024 13:10:37 -0700 Subject: [PATCH 2/2] Initialize AvailableBasemaps and improve load check Add initialization flag for BasemapGallery collection --- .../BasemapGallery/BasemapGallery.Windows.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs b/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs index 6695a7f2d..314bef103 100644 --- a/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs +++ b/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs @@ -34,6 +34,7 @@ namespace Esri.ArcGISRuntime.Toolkit.UI.Controls public partial class BasemapGallery : Control { private readonly BasemapGalleryController _controller; + private bool isAvailableBasemapCollectionInitialized; /// /// Initializes a new instance of the class. @@ -43,6 +44,8 @@ public BasemapGallery() _controller = new BasemapGalleryController(); DefaultStyleKey = typeof(BasemapGallery); SizeChanged += BasemapGallerySizeChanged; + AvailableBasemaps = new ObservableCollection(); + isAvailableBasemapCollectionInitialized = true; _controller.PropertyChanged += HandleControllerPropertyChanged; Loaded += BasemapGallery_Loaded; } @@ -52,7 +55,7 @@ private async void BasemapGallery_Loaded(object? sender, RoutedEventArgs e) // Unsubscribe from the Loaded event to ensure this only runs once. Loaded -= BasemapGallery_Loaded; - if (AvailableBasemaps is null) + if ((AvailableBasemaps is null || !AvailableBasemaps.Any()) && isAvailableBasemapCollectionInitialized) { await _controller.LoadFromDefaultPortal(); } @@ -140,6 +143,7 @@ private static void AvailableBasemapsChanged(DependencyObject d, DependencyPrope { if (d is BasemapGallery gallery) { + gallery.isAvailableBasemapCollectionInitialized = false; if (e.NewValue != gallery._controller.AvailableBasemaps) { gallery._controller.AvailableBasemaps = e.NewValue as IList;