首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF this.NavigationService.Navigate

WPF this.NavigationService.Navigate
EN

Stack Overflow用户
提问于 2019-02-18 15:30:58
回答 1查看 2.4K关注 0票数 1

我正在从Microsoft网站学习WPF教程,该教程如下:

https://learn.microsoft.com/en-us/dotnet/framework/wpf/getting-started/walkthrough-my-first-wpf-desktop-application#add-code-to-handle-events

我从代码中得到以下错误:

代码语言:javascript
复制
private void Button_Click(object sender, RoutedEventArgs e)
{
    //View Expense Report
    ExpenseReportPage expenseReportPage = new ExpenseReportPage(); //Line 1
    this.NavigationService.Navigate(expenseReportPage); // Line 2
}

以上代码中的第2行为NavigationService提供了以下错误:

“无效-全局-代码”不包含“NavigationService”的定义,并且无法找到接受类型'‘的第一个参数的可访问扩展方法'NavigationService’(您是缺少使用指令还是程序集引用?)

我添加了使用中的this.NavigationService.Navigate(expenseReportPage);;我认为问题来自于System.Windows.Navigation的“这个”部分

EN

回答 1

Stack Overflow用户

发布于 2019-02-18 16:02:13

Window元素更改为NavigationWindow元素,或将Frame元素添加到窗口并访问其NavigationService属性:

代码语言:javascript
复制
frame.NavigationService.Navigate(expenseReportPage); // Line 2

XAML:

代码语言:javascript
复制
<Window ...>
    <Frame x:Name="frame" />
</Window>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54750564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档