简体   繁体   中英

NavigationService doesn't have a definition

I want a forward button in my MainWindow.xaml to navigatie in my history to the correct pages. This is what I added to my Backbutton click:

private void BackClick(object sender, MouseButtonEventArgs e)
    {
        if (this.NavigationService.CanGoBack)
        {
            this.NavigationService.GoBack();
        }
    }

The error that keeps being dispayed is

'MainWindow' does not contain a definition for 'NavigationService'

As far as I know my import are correct

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Navigation;
using System.ComponentModel;

The

this.NavigationService

property does not exist in your MainWindow class. Read the docs for more information. You need to access the NavigationService from a Frame , Page or NavigationWindow .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM