diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs index 75c54f1f6476..b87f2b52bbbe 100644 --- a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs @@ -40,7 +40,7 @@ public RefreshContainerOnImagePage() { this.InitializeComponent(); this.Loaded += OnMainPageLoaded; - + this.Unloaded += OnMainPageUnloaded; timer.Interval = new TimeSpan(0, 0, 0, 0, 800); timer.Tick += Timer_Tick; } @@ -50,13 +50,10 @@ public RefreshContainerOnImagePage() private bool delayRefresh = true; private int refreshCount = 0; - protected -#if HAS_UNO - internal -#endif - override void OnNavigatedFrom(NavigationEventArgs e) + // Uno specific: Unlike WinUI, we unsubscribe on Unloaded because we don't get OnNavigatedFrom. + // See point #2 in https://github.com/unoplatform/uno/issues/15059#issuecomment-1891551501 + private void OnMainPageUnloaded(object sender, RoutedEventArgs e) { - base.OnNavigatedFrom(e); timer.Stop(); } diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerPage.xaml.cs b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerPage.xaml.cs index 93eaacae1e32..805d7102e682 100644 --- a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerPage.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerPage.xaml.cs @@ -60,6 +60,7 @@ public RefreshContainerPage() { this.InitializeComponent(); this.Loaded += OnMainPageLoaded; + this.Unloaded += OnMainPageUnloaded; containerTimer.Interval = new TimeSpan(0, 0, 0, 5, 0); containerTimer.Tick += containerTimer_Tick; @@ -68,13 +69,10 @@ public RefreshContainerPage() LogController.InitializeLogging(); } - protected -#if HAS_UNO - internal -#endif - override void OnNavigatedFrom(NavigationEventArgs e) + // Uno specific: Unlike WinUI, we unsubscribe on Unloaded because we don't get OnNavigatedFrom. + // See point #2 in https://github.com/unoplatform/uno/issues/15059#issuecomment-1891551501 + private void OnMainPageUnloaded(object sender, RoutedEventArgs e) { - base.OnNavigatedFrom(e); containerTimer.Stop(); visualizerTimer.Stop(); }