Robert Höglund
Robert Höglund

Reputation: 10070

How to add a Page to Frame using code in 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).

Upvotes: 10

Views: 45567

Answers (2)

BASIR ALMAS
BASIR ALMAS

Reputation: 1

yourFramName.NavigationService.Navigate(yourPageObject)

e.g Frame1.NavigationService.Navigate(new Page1());

Upvotes: -2

Joachim Kerschbaumer
Joachim Kerschbaumer

Reputation: 9871

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

Upvotes: 19

Related Questions