WPF NavigationService.Navigate 未显示在 Expression Blend 中 [英] WPF NavigationService.Navigate not showing up in Expression Blend

查看:34
本文介绍了WPF NavigationService.Navigate 未显示在 Expression Blend 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建 WPF 应用程序,但无法在按钮单击事件上导航到自定义 xaml 文件.我正在导入导航服务方法,但由于某种原因NavigationService.Navigate"没有出现.它只向我显示 NavigationService.GetNavigationService.谁能告诉我可能是什么问题?

I am trying to create a WPF application but I cannot navigate to a custom xaml file on a button click event. I am importing the navigation service method but for some reason the "NavigationService.Navigate" is not showing up. It only shows me NavigationService.GetNavigationService. Can anyone give me an idea what the issue might be?

推荐答案

NavigationService.Navigate 是 Page 对象的一部分.如果您从

NavigationService.Navigate is part of Page object. If you inherit your XAML from

public partial class MainWindow : Page

代替

public partial class MainWindow : Window

如果你想从主窗口导航到一个页面,请在主窗口中创建一个框架,如下所示

If you want to navigate to a page from main window create a frame in mainwindow as below

<DockPanel>
        <Frame x:Name="_NavigationFrame" NavigationUIVisibility="Hidden" />
</DockPanel>

然后在你的主窗口构造函数中调用

and then in your mainwindow constructor call

_NavigationFrame.Navigate(new CustomXml());

_NavigationFrame.Navigate(new CustomXml());

对不起,CustomXaml 只是 CustomPage 的名称.

Sorry for the confusion CustomXaml is just the name of CustomPage.

我将使用以下页面导航应用程序设计

I will use the following design for page navigation application

步骤 1:创建 MainWindow.Xaml 并添加以下代码

Steps 1: Create MainWindow.Xaml and add the following Code

 <DockPanel>
            <Frame x:Name="_NavigationFrame" NavigationUIVisibility="Hidden" />
 </DockPanel>

Frame 是所有页面的占位符.

Frame is a placeholder for all the pages.

第 2 步:创建主页 MainPage.xaml(如主页)并将您打算放置在 MainWindow.XAML 中的所有代码放入此 MainPage.XAML.要在应用程序加载时打开此主页,请在 MainWindow.Xaml 构造函数中添加以下代码

Step 2: Create a main page MainPage.xaml (like home page) and place all the code you intend to place in MainWindow.XAML into this MainPage.XAML. To open this main page on application load add the following code in MainWindow.Xaml constructor

_NavigationFrame.Navigate(new MainPage());其中 MainPage() 是 MainPage.XAML 的构造函数

_NavigationFrame.Navigate(new MainPage()); where MainPage() is the constructor of MainPage.XAML

第 3 步:创建自定义页面 CustomPage.XAML(您要导航到的页面).为了从第一页导航到这个页面

Step 3: Create a custom Page CustomPage.XAML (the page you want to navigate to). In order to navigate to this page from first page

this.NavigationService.Navigate(new Uri("CustomPage.xaml", UriKind.Relative));

这篇关于WPF NavigationService.Navigate 未显示在 Expression Blend 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆