How to create a Frame in WPF?

The Frame control in WPF supports content navigation within content. A Frame can be hosted within a Window, NavigationWindow, Page, UserControl, or a FlowDocument control.

This XAML code shows how to create a Frame control and sets its Source property to load a XAML page within it.

<Window x:Class="FrameSample.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>       

        <TextBlock>Outside area of frame</TextBlock>

        <Frame Source="Page1.xaml">           

        </Frame>

    </Grid>

</Window>

 

The Window looks like this. The purple area is the Page1.xaml and white area is outside of the Frame.

FrameImg1.gif

Now you can manage contents of a frame the way you want.

For example, the following code rotates the contents of frame to 45 angle.

<Frame Source="Page1.xaml">

    <Frame.LayoutTransform>

        <RotateTransform Angle="45" />

    </Frame.LayoutTransform>

</Frame>

The new output looks like this.

FrameImg2.gif