你好,我已经被困在这里三天了,尝试了很多可能性。我有一个名为'Mainwindow.xaml'
的WPF窗口,我想要导航到一个名为'addNewTech.xaml'
的WPF页面,并保持'Manwindow.xaml'
在后台打开,请帮助我解决这个问题。谢谢。
首先,在MainWindow中添加Frame
。
例如:
使用此命名空间xmlns:local="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
<Grid>
<local:Frame Name="MainFrame" NavigationUIVisibility="Hidden" >
</local:Frame>
</Grid>
MainWindow.cs
中调用AddNewTech
以将页面加载到主窗口。MainFrame.Navigate(new Uri("addNewTech.xaml",UriKind.Relative));
NavigationService navService = NavigationService
.GetNavigationService(this)
navService.Navigate = (new
System.Uri("Page2.xaml",UriKind.RelativeOrAbsolute);
或者
Page2 nextPage = new Page2();
navService.Navigate(nextPage);
或者
Page2 page2Obj = new Page2(); //Create object of Page2
page2Obj.Show(); //Show page2 this.Close(); //this will close Page1
addNewTech.xaml
必须在根目录中。否则请使用以下方式:MainFrame.Navigate(new Uri("foldername/addNewTech.xaml",UriKind.Relative));
- ebattulgaGrid
的宽度和高度是否不为0,并且addNewTech.xaml
文件中是否包含任何可见内容。 - ebattulga