WPF Frame


The Frame is a WPF built-in content control that does not have the notion of being clicked like a button. The Frame control holds any content, but it isolates the content from the rest of the user interface. Properties that would normally be inherited down the element tree stop when they reach the Frame. WPF Frames act like frames in HTML. In this category is also the Label and the ToolTip. These three are known as simple containers. The Frame control can hold arbitrary content, just like all other content controls, but it isolates the content from the rest of the user interface. What does that mean? Properties that would normally be inherited down the element tree stop when they reach the frame. The Frame can render HTML content in addition to WPF content. The Frame has a Source property of type System.Uri that can be set to any HTML (or XAML) page. Here is an example.

This simple project uses two XAML files and does not need to make any changes to the code-behind. The second XAML file, Page1.xaml, is created by right-clicking the project in Solution Explorer and choosing Add > Page. Below are the two XAML files.

<Window x:Class="FrameSimple.MainWindow"
        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"
        xmlns:local="clr-namespace:FrameSimple"
        mc:Ignorable="d"
        WindowStartupLocation="CenterScreen"
        Title="FrameSimple" Height="250" Width="300">
    <Grid Margin="4">
        <TextBlock>Outside the area of the frame</TextBlock>
        <Frame Source="Page1.xaml">
            <Frame.LayoutTransform>
                <RotateTransform Angle="10" />
            </Frame.LayoutTransform>
        </Frame>
    </Grid>
</Window>

Here is the Page1.xaml. Notice that the Frame has a Source property that points to a XAML file.

<Page x:Class="FrameSimple.Page1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:FrameSimple"
      mc:Ignorable="d" 
      d:DesignHeight="100" d:DesignWidth="150"
      Title="Page1" MaxWidth="150" MaxHeight="100">
    <Grid Background="MediumPurple">
        <TextBlock Margin="2">a Grid inside a XAML</TextBlock>
    </Grid>
</Page>