如何在 C#(3.0) 中从 wpf 窗口导航到 wpf 页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15104923/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 14:04:13  来源:igfitidea点击:

how to navigate from a wpf window to wpf page in C#(3.0)?

c#wpf

提问by user2067120

Hey i'm stucked here from last 3 days and tried as hell of possibilities, I have wpf window called 'Mainwindow.xaml'i want to navigate a wpf page named 'addNewTech.xaml'keeping 'Manwindow.xaml'open in background please help me out.. Thank you..

嘿,我从过去 3 天起就被困在这里,并尝试了各种可能性,我有'Mainwindow.xaml'一个名为 wpf 的窗口,我想导航一个名为在后台'addNewTech.xaml'保持'Manwindow.xaml'打开的 wpf 页面,请帮帮我..谢谢..

回答by Pranali Desai

 NavigationService navService = NavigationService
 .GetNavigationService(this) 

navService.Navigate =  (new
 System.Uri("Page2.xaml",UriKind.RelativeOrAbsolute); 

OR

或者

 Page2 nextPage = new Page2();

 navService.Navigate(nextPage);

OR

或者

 Page2 page2Obj = new Page2(); //Create object of Page2


 page2Obj.Show(); //Show page2 this.Close(); //this will close Page1

回答by ebattulga

First. Add Framein MainWindow.

第一的。Frame在主窗口中添加。

For example:

例如:

Use this namespace xmlns:local="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"

使用这个命名空间 xmlns:local="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"

<Grid>
   <local:Frame Name="MainFrame" NavigationUIVisibility="Hidden" >                            
   </local:Frame>
</Grid>

call AddNewTechin MainWindow.csto load page into MainWindow.

调用AddNewTechMainWindow.cs将页面加载到 MainWindow。

MainFrame.Navigate(new Uri("addNewTech.xaml",UriKind.Relative));