Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavigationService does not navigate to a different page. #1201

Open
chocoOnEstrogen opened this issue Aug 15, 2024 · 0 comments
Open

NavigationService does not navigate to a different page. #1201

chocoOnEstrogen opened this issue Aug 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@chocoOnEstrogen
Copy link

chocoOnEstrogen commented Aug 15, 2024

Describe the bug

When using NavigationService.Navigate(...) it does not Navigate to the proper page, however it throws an error.

"Object reference not set to an instance of an object."

The code is as follows:

private void OnUserCardClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    UserPage userPage = new UserPage(new UserViewModel());
    NavigationService.Navigate(userPage);
}

I do not know if this is the proper way, the documentation states:

Navigate(string)

Even using this does not work.

// SearchPage.xaml.cs
UserPage userPage = new UserPage(new UserViewModel(), new NavigationView());
NavigationService.Navigate(userPage);

// UserPage.xaml.cs

public UserPage(
    UserViewModel viewModel,
    NavigationView navigationView
)
{
    ViewModel = viewModel;
}

EDIT:

The error comes from a global error handler

 App.Current.DispatcherUnhandledException += OnDispatcherUnhandledException;
 AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;

private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            // Handle the exception and show an error message
            ShowErrorMessage("An unexpected error occurred: " + e.Exception.Message);
            e.Handled = true; // Mark the exception as handled
        }

        private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            // Handle the exception and show an error message
            if (e.ExceptionObject is Exception ex)
            {
                ShowErrorMessage("An unexpected error occurred: " + ex.Message);
            }
        }

        private void ShowErrorMessage(string message)
        {
            // You can customize this to show a dialog or error window
            System.Windows.MessageBox.Show(message, "Error", System.Windows.MessageBoxButton.OK, MessageBoxImage.Error);
        }

To Reproduce

UserPage userPage = new UserPage(new UserViewModel());
NavigationService.Navigate(userPage);

Expected behavior

The page should navigate the the proper page.

Screenshots

Main Issue Video

devenv_J9JXoCoXje.mp4

UserViewModel.cs

image

OS version

Windows 11

.NET version

8.0.400

WPF-UI NuGet version

3.0.4

Additional context

No response

@chocoOnEstrogen chocoOnEstrogen added the bug Something isn't working label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant