WPF Reflections

Sep 27 2008   5:15PM GMT

WPF pages hosting in pages

Mark Shurmer Profile: MarkWPF

What do I mean by that?

Simply put, you can embed a page within another page.
Why would you want to do that?
It allows re-use for a start, as well as splitting functionality down into logical chunks.

In the following example, I have done just that:

First the top level window

<Window x:Class=”BlogSept.Window1″
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
Title=”Window1″ Height=”300″ Width=”300″>
<Grid>
<Frame Source=”page1.xaml” NavigationUIVisibility=”Visible”>
</Frame>
</Grid>
</Window>

Then page1

<Page x:Class=”BlogSept.Page1″
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
Title=”Page1″>
<Grid>
<Rectangle Margin=”46,68,54,132″ Name=”rectangle1″ Stroke=”Black” Fill=”Chocolate” OpacityMask=”Beige” Opacity=”0.6″ />
<TextBox Text=”Random text” Margin=”80, 190, 10, 10″ />
<Frame Source=”page2.xaml” />
</Grid>
</Page>

Notice how it embeds a copy of page2 inside it’s visual tree.
Here is page 2:

<Page x:Class=”BlogSept.Page2″
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
Title=”Page2″>
<Grid>
<Ellipse Margin=”42,71,64,118″ Name=”ellipse1″ Stroke=”Black” Fill=”BlueViolet” />
</Grid>
</Page>

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: