7

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/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.

4 Answers 4

18

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());
1
  • also do NOT forget to remove width and height properties inside the Page.xaml.
    – A.B.
    Mar 5, 2020 at 16:26
3

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

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

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

1
  • how to load that frame in center of screen ? Jul 10, 2015 at 5:38
0

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());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.