From 4f0fa2da19fc8a6c255b5f9cabba4a0a09db2056 Mon Sep 17 00:00:00 2001 From: Prathamesh Narkhede Date: Wed, 12 Jun 2024 11:28:19 -0700 Subject: [PATCH] Unsubscribe from Loaded event in BasemapGallery --- src/Toolkit/Toolkit.Maui/BasemapGallery/BasemapGallery.cs | 3 +++ .../BasemapGallery/BasemapGallery.Windows.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Toolkit/Toolkit.Maui/BasemapGallery/BasemapGallery.cs b/src/Toolkit/Toolkit.Maui/BasemapGallery/BasemapGallery.cs index 7597dea50..3e28f8767 100644 --- a/src/Toolkit/Toolkit.Maui/BasemapGallery/BasemapGallery.cs +++ b/src/Toolkit/Toolkit.Maui/BasemapGallery/BasemapGallery.cs @@ -49,6 +49,9 @@ public BasemapGallery() private async void BasemapGallery_Loaded(object? sender, EventArgs e) { + // Unsubscribe from the Loaded event to ensure this only runs once. + Loaded -= BasemapGallery_Loaded; + if (AvailableBasemaps is null) { _loadCancellationTokenSource = new CancellationTokenSource(); diff --git a/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs b/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs index dd6cc8258..93edb92d2 100644 --- a/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs +++ b/src/Toolkit/Toolkit.UI.Controls/BasemapGallery/BasemapGallery.Windows.cs @@ -53,6 +53,9 @@ public BasemapGallery() 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) { _loadCancellationTokenSource = new CancellationTokenSource();