D
D
Dexaid2282020-12-16 14:56:26
WPF
Dexaid228, 2020-12-16 14:56:26

Why doesn't redirect to another window work in WPF?

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (seven.IsChecked == true) 
            {
                NavigationService nav = NavigationService.GetNavigationService(this);
                nav.Navigate(new Uri("/SevenCalss.xaml", UriKind.Relative));
            }
            if (eight.IsChecked == true)
            {
                NavigationService nav = NavigationService.GetNavigationService(this);
                nav.Navigate(new Uri("/EightClass.xaml", UriKind.Relative));
            }
            if (nine.IsChecked == true)
            {
                NavigationService nav = NavigationService.GetNavigationService(this);
                nav.Navigate(new Uri("/NineCalss.xaml", UriKind.Relative));
            }
        }
    }
}


I googled how to redirect the user to another window after pressing the button, but for some reason it does not redirect to another page, but just when I press the button it freezes for a second and that's it, nothing happens, tell me why this can be.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris the Animal, 2020-12-16
@Casper-SC

See a working example implementation here:
How to navigate between pages in Windows Presentation Foundation?
You just have a window open and the service is called in it. This does not mean that MainWindow will close and a new window will open. You need to use either Frame or NavigationWindow (help supports Russian, change en-us to ru-ru).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question