Load target view's data before transitioning

This commit is contained in:
Pat Hartl 2026-07-05 01:29:56 -05:00
parent 545b5b1f43
commit 16495770ba

View file

@ -49,17 +49,17 @@ public partial class NavigationService : ObservableObject, INavigationService
}
// Show the loading overlay and yield so the UI thread can paint it
// BEFORE the heavy view creation from the ContentControl DataTemplate.
// over the CURRENT view before we do any heavy work.
IsNavigating = true;
await Dispatcher.UIThread.InvokeAsync(() => { }, DispatcherPriority.Render).GetTask();
CurrentView = viewModel;
try
{
if (initializeAsync != null)
await initializeAsync();
CurrentView = viewModel;
// Yield again so the new view finishes layout/render
// before we hide the overlay.
await Dispatcher.UIThread.InvokeAsync(() => { }, DispatcherPriority.Background).GetTask();
@ -67,6 +67,8 @@ public partial class NavigationService : ObservableObject, INavigationService
catch
{
// Initialization errors are handled by the caller's callback.
// Still swap to the target view so navigation isn't left stuck.
CurrentView = viewModel;
}
finally
{