Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading page in WPF

Tags:

wpf

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.

like image 312
Shift Avatar asked Mar 30 '10 18:03

Shift


2 Answers

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());
like image 50
astreal Avatar answered Sep 21 '22 12:09

astreal


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

frame1.Source = new Uri("Page1.xaml", UriKind.RelativeOrAbsolute);
like image 44
Shift Avatar answered Sep 19 '22 12:09

Shift