wpf 在同一窗口中导航到新页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19462474/
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
Navigate to new page in same window
提问by user2602079
I want to click a button and navigate to a new page, not make a second window appear over top of the first window. The pages are the view of complex code (e.g., the actual game). I don't really want to use a navigation window because i don't want forward and back arrows appearing. The error on the code below is that "ns" (NavigationService) is null. How do I make want I want to do work?
我想单击一个按钮并导航到一个新页面,而不是让第二个窗口出现在第一个窗口的顶部。页面是复杂代码(例如,实际游戏)的视图。我真的不想使用导航窗口,因为我不想出现向前和向后箭头。下面代码的错误是“ns”(NavigationService)为空。我如何想要我想做的工作?
private void btnLevelDesigner_Click(object sender, RoutedEventArgs e)
{
NavigationService ns = NavigationService.GetNavigationService(this);
LevelDesignerPage levelDesignerPage = new LevelDesignerPage();
ns.Navigate(levelDesignerPage);
}


回答by Ondra
I would insert a Frame into your main window - http://msdn.microsoft.com/en-us/library/system.windows.controls.frame.aspx
我会在您的主窗口中插入一个框架 - http://msdn.microsoft.com/en-us/library/system.windows.controls.frame.aspx
This Frame has NavigationService property that allows you to change content of the frame. It should be also available to acces the navigation service from inside content of the frame.
此 Frame 具有 NavigationService 属性,允许您更改框架的内容。它也应该可用于从框架的内部内容访问导航服务。
Regarding the Back/forward arrows - Take a look at ShowNavigationUIProperty
关于后退/前进箭头 - 看看ShowNavigationUI属性

