在WPF中加载页面

Shi*_*ift 6 wpf

伙计们,我有一个基本的WPF应用程序.像往常一样包含App.xaml和Mainwindow.xaml.我也创建了一些页面,如page1/2/3.我想在mainwindow.xaml中加载例如page1.xaml.这可能吗?并且还想关闭它,以便mainwindow.xaml的内容将保留在那里.

我不希望这是一个导航应用程序,顶部有左/右箭头.

ast*_*eal 15

我来到这里补充一点,有很多方法可以将页面加载到框架中:

通过设置源(如提到的@Shift)

frame1.Source = new Uri("Page1.xaml", UriKind.RelativeOrAbsolute);
Run Code Online (Sandbox Code Playgroud)

通过设置内容:

frame1.Content= new Page1();
Run Code Online (Sandbox Code Playgroud)

通过使用NavigationService:

frame1.NavigationService.Navigate(new Page1());
Run Code Online (Sandbox Code Playgroud)


Mau*_*lli 1

您可以向主页添加框架并加载其上的页面。