开发者

Loading page in WPF

开发者 https://www.devze.com 2022-12-25 07:21 出处:网络
Guys, I have a basic WPF application. Contains App.xaml as always and a Mainwindow.xaml. I\'ve created also some pages like page1/2开发者_StackOverflow/3. I want to load for example page1.xaml in main

Guys, I have a basic WPF application. Contains App.xaml as always and a Mainwindow.xaml. I've created also some pages like page1/2开发者_StackOverflow/3. I want to load for example page1.xaml in mainwindow.xaml. Is this possible? And also want to close it so the content of mainwindow.xaml will stay in there.

I dont want this to be a navigation application with the left/right arrows at the top.


I came here to add that there are many ways to load the pages into the frame:

By setting the source (as @Shift mentioned)

frame1.Source = new Uri("Page1.xaml", UriKind.RelativeOrAbsolute);

By setting the Content:

frame1.Content= new Page1();

By using the NavigationService:

frame1.NavigationService.Navigate(new Page1());


Adding a frame and setting the source for the frame like makes my day :)

frame1.Source = new Uri("Page1.xaml", UriKind.RelativeOrAbsolute);


You can add a frame to your main page and load the pages on it.


Call below navigate function from inside any control or verification area.Page1 is the new page.So it opens like a new window from the application.

    NavigationWindow navigationWdw = new NavigationWindow();
    navigationWdw.Height = this.Height;
    navigationWdw.Width = this.Width;
    navigationWdw.Show();
    navigationWdw.Navigate(new Page1());
0

精彩评论

暂无评论...
验证码 换一张
取 消