WPF NavigationService.Navigate 未显示在 Expression Blend 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17071180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF NavigationService.Navigate not showing up in Expression Blend
提问by nishantvodoo
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?
我正在尝试创建 WPF 应用程序,但无法导航到按钮单击事件上的自定义 xaml 文件。我正在导入导航服务方法,但由于某种原因“NavigationService.Navigate”没有出现。它只向我显示 NavigationService.GetNavigationService。谁能给我一个想法可能是什么问题?


回答by Jasti
NavigationService.Navigate is part of Page object. If you inherit your XAML from
NavigationService.Navigate 是 Page 对象的一部分。如果您从
public partial class MainWindow : Page
instead of
代替
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());
EDIT:
编辑:
Sorry for the confusion CustomXaml is just the name of CustomPage.
很抱歉混淆 CustomXaml 只是 CustomPage 的名称。
I will use the following design for page navigation application
我将使用以下设计进行页面导航应用程序
Steps 1: Create MainWindow.Xaml and add the following Code
步骤 1:创建 MainWindow.Xaml 并添加以下代码
<DockPanel>
<Frame x:Name="_NavigationFrame" NavigationUIVisibility="Hidden" />
</DockPanel>
Frame is a placeholder for all the pages.
Frame 是所有页面的占位符。
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
第 2 步:创建一个主页 MainPage.xaml(如主页)并将您打算放置在 MainWindow.XAML 中的所有代码放入此 MainPage.XAML。要在应用程序加载时打开此主页,请在 MainWindow.Xaml 构造函数中添加以下代码
_NavigationFrame.Navigate(new MainPage());where MainPage() is the constructor of MainPage.XAML
_NavigationFrame.Navigate(new MainPage());其中 MainPage() 是 MainPage.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
步骤 3:创建自定义页面 CustomPage.XAML(您要导航到的页面)。为了从第一页导航到此页面
this.NavigationService.Navigate(new Uri("CustomPage.xaml", UriKind.Relative));

