diff --git a/tools/Dashboard/DevHome.Dashboard/ViewModels/WidgetViewModel.cs b/tools/Dashboard/DevHome.Dashboard/ViewModels/WidgetViewModel.cs index 10b90cafd6..53d769fea0 100644 --- a/tools/Dashboard/DevHome.Dashboard/ViewModels/WidgetViewModel.cs +++ b/tools/Dashboard/DevHome.Dashboard/ViewModels/WidgetViewModel.cs @@ -323,4 +323,9 @@ private async void HandleWidgetUpdated(Widget sender, WidgetUpdatedEventArgs arg Log.Logger()?.ReportDebug("WidgetViewModel", $"HandleWidgetUpdated for widget {sender.Id}"); await RenderWidgetFrameworkElementAsync(); } + + public void UnsubscribeFromWidgetUpdates() + { + Widget.WidgetUpdated -= HandleWidgetUpdated; + } } diff --git a/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs b/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs index 54fe811154..4c8792f3b7 100644 --- a/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs +++ b/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs @@ -18,6 +18,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Navigation; using Microsoft.Windows.Widgets; using Microsoft.Windows.Widgets.Hosts; using Windows.System; @@ -510,6 +511,17 @@ private async void WidgetControl_Drop(object sender, DragEventArgs e) Log.Logger()?.ReportDebug("DashboardView", $"Drop ended"); } + protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) + { + Log.Logger()?.ReportDebug("DashboardView", $"Leaving Dashboard, deactivating widgets."); + + // Deactivate widgets if we're not on the Dashboard. + foreach (var widget in PinnedWidgets) + { + widget.UnsubscribeFromWidgetUpdates(); + } + } + #if DEBUG private void AddResetButton(object sender, RoutedEventArgs e) {