首页 > 解决方案 > NavigationService 没有定义

问题描述

我希望 MainWindow.xaml 中有一个前进按钮,以便在我的历史记录中导航到正确的页面。这是我添加到我的后退按钮单击的内容:

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

不断显示的错误是

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

据我所知,我的导入是正确的

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

标签: c#wpf

解决方案


this.NavigationService

您的课程中不存在该属性MainWindow。阅读文档以获取更多信息。您需要NavigationServiceFramePage访问NavigationWindow


推荐阅读