Search code examples
c#wpfwpf-4.0

WPF: Frame NavigationService GoBack request is not working


In my WPF appln, I have a Dialog window with couple of buttons and For each button click I can Navigate the pages in the MainWindow by "Frame.Navigate(_page);" .But from the page I am unable to go back my previous dialog window. I used "Frame.NavigationService.GoBack();". But it is not going back to the Dialog window.It is not moving out from the MainWindow. Can Anyone please resolve my problem?


Solution

  • Go back can happen only when navigationService.CanGoBack is true. Ensure the value of this property. You can go back if navigation is done earlier. This actually functions similar to undo redo. Also I verified with following snippet that works fine for me,

    NavigationService service;
    public MainWindow()
    {
        InitializeComponent();
        service = mainframe.NavigationService;
        service.Navigate("Page2.xaml");
    }
    
    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        if (service.CanGoBack)
            service.GoBack();
    }