diff --git a/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs b/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs index 66ecfb5f8..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. @@ -44,6 +45,7 @@ public BasemapGallery() DefaultStyleKey = typeof(BasemapGallery); SizeChanged += BasemapGallerySizeChanged; AvailableBasemaps = new ObservableCollection(); + isAvailableBasemapCollectionInitialized = true; _controller.PropertyChanged += HandleControllerPropertyChanged; Loaded += BasemapGallery_Loaded; } @@ -52,8 +54,8 @@ 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(); } @@ -141,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;