silverlight – WP7 Frame embedded in a page linking to another page – Education Career Blog

I have a xaml page that I want to host another xaml page for various reasons. I attempted to use the Frame control, but I ended up with a warning telling me that the default constructor must be public…

<controls:PivotItem Header="page1">
    <Controls:Frame Source="MyPage.xaml"/>
</controls:PivotItem>

Okay, well that doesn’t work; now how exactly do I embed a page inside of another page in a WP7 application?

,

This is a typical layout of a XAML page with a Pivot –

<controls:Pivot x:Name="mainPivot" Title="Home">
    <controls:Pivot.Items>
        <controls:PivotItem Header="Page 1" x:Name="Page1">
            <controls:PivotItem.Content>
                <views:Page1View />
            </controls:PivotItem.Content>
        </controls:PivotItem>
        <controls:PivotItem Header="Page 2" x:Name="page2">
            <controls:PivotItem.Content>
                <views:Page2View />
            </controls:PivotItem.Content>
        </controls:PivotItem>
        <controls:PivotItem Header="Page 3" x:Name="Page3">
            <controls:PivotItem.Content>
                <views:Page3View />
            </controls:PivotItem.Content>
        </controls:PivotItem>
    </controls:Pivot.Items>
</controls:Pivot>

The views namespace is declared within the XAML as –

xmlns:views="clr-namespace:MyApp.Views" 

Each view will be in their individual XAML files, for example (Page1View.xaml) looks like this –

<UserControl 
    x:Class="MyApps.Views.Page1View"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="600" 
    d:DesignWidth="480">

    <Grid x:Name="LayoutRoot">
       <!-- Add your content here -->
    </Grid>
</UserControl>

Hope this helps,
indyfromoz

Leave a Comment