I'm developing a WinUI 3 app using Template Studio with a Navigation Bar. The INavigationService
has a NavigateTo
method that I can use to navigate between custom pages like Login
and SignUp
. However, I'm having an issue where I can't navigate to ShellPage
after a successful login.
Specifically, the following code doesn't work as expected:
private readonly INavigationService _navigationService;
private UIElement? _shell;
public LoginViewModel(IAuthService authService, INavigationService navigationService)
{
_authService = authService;
_navigationService = navigationService;
}
if (loginSuccessful)
{
// Not working in this context
_navigationService.NavigateTo(typeof(ShellViewModel).FullName!);
// Works but doesn't show full content of ShellPage (doesn't automatically activate BlankPage)
var shell = App.GetService<ShellPage>();
App.MainWindow.Content = shell ?? (UIElement)new Frame();
}
Interestingly, if I use NavigateTo
with custom pages like SignUp
, it works fine:
public void NavigateToSignUp()
{
_navigationService.NavigateTo(typeof(SignUpViewModel).FullName!);
}
When i'm using:
// Works but doesn't show full content of ShellPage (doesn't automatically activate BlankPage) var shell = App.GetService<ShellPage>();
App.MainWindow.Content = shell ?? (UIElement)new Frame();
I got:
But i'm expect:
Question: How can I successfully navigate to ShellPage
after login and ensure that ShellPage
displays its full content