Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a Page to Frame using code in WPF

Tags:

wpf

I have a Window where I have put a Frame. I would like to add a Page to the Frame when I click a button that is also on the Window but not in the Frame. There are several buttons in the Window and each click on a button should load a different Page in the Frame.

Since I'm a total newbie on this WPF stuff it's quite possible that this approach is not the best and I have thought about replacing the Frame with a Canvas and then make UserControls instead of Pages that will be added to the Canvas. I welcome any ideas and suggestions on how to best solve this.

I aiming for a functionality that is similar to the application Billy Hollis demonstrated in dnrtv episode 115. (http://dnrtv.com/default.aspx?showID=115).

like image 450
Robert Höglund Avatar asked Sep 26 '08 07:09

Robert Höglund


People also ask

How do I add a page in WPF?

Step 1: Create an empty WPF using Visual Studio, enter the name for the application and click on OK. Step 2: Create a button using the following code or drag and drop a button from the ToolBox of Visual Studio 2013.

How do I redirect a page to another page in WPF?

It is possible and there are various ways of achieving this... If you create a new WPF project in VS it will create a MainWindow. Add a new window, by default it will be called Window1. If you place a button on MainWindow and under the click event of the button put the following code...

What is a frame in WPF?

The Frame control supports content navigation within content. Frame can be hosted by a root element like Window, NavigationWindow, Page, UserControl, FlowDocument, or as an island within a content tree that belongs to a root element.

How do I navigate between windows in WPF?

NavigationService is for browser navigation within WPF. What you are trying to do is change to a different window TrainingFrm . To go to a different window, you should do this: private void conditioningBtn_Click(object sender, RoutedEventArgs e) { var newForm = new TrainingFrm(); //create your new form.


1 Answers

the Frame class exposes a method named "Navigate" that takes the content you want to show in your frame as parameter. try calling

myFrame.Navigate(myPageObject);

this should work

like image 123
Joachim Kerschbaumer Avatar answered Oct 15 '22 03:10

Joachim Kerschbaumer