Page loading in WPF

Guys, I have a main WPF application. Contains App.xaml, as always, and Mainwindow.xaml. I also created some pages, such as page1 / 2/3. I want to load, for example, page1.xaml in mainwindow.xaml. Is it possible? And also want to close it so that the contents of mainwindow.xaml remain there.

I don't want this to be a navigation app with left / right arrows at the top.

+4
source share
3 answers

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

0
source

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

By setting the source (as @Shift pointed out)

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

By setting the contents:

 frame1.Content= new Page1(); 

Using NavigationService :

 frame1.NavigationService.Navigate(new Page1()); 
+11
source

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

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

Source: https://habr.com/ru/post/1305589/


All Articles