Xaml 将页面加载到ContentControl中

Xaml 将页面加载到ContentControl中,xaml,windows-8,windows-runtime,winrt-xaml,contentcontrol,Xaml,Windows 8,Windows Runtime,Winrt Xaml,Contentcontrol,我有一个ContentControl,我想在其中加载页面myPage2。此页面中我的XAML代码如下所示: <Page x:Class="ExampleApp.myPage2"> <Grid x:Name="Content" Height="651" Width="941" Background="White"> ... ... </Grid> </Page> <UserControl x:C

我有一个ContentControl,我想在其中加载页面myPage2。此页面中我的XAML代码如下所示:

<Page x:Class="ExampleApp.myPage2">
    <Grid x:Name="Content" Height="651" Width="941" Background="White">
        ...
        ...
    </Grid>
</Page>
<UserControl x:Class="ExampleApp.myControl2">
    <Grid x:Name="Content" Height="651" Width="941" Background="White">
        ...
        ...
    </Grid>
</UserControl>
我现在的问题是,我不能用这些代码加载上面这样的页面。我必须写下:

<Page x:Class="ExampleApp.myPage2">
    <Page.Resources> 
        <DataTemplate x:Key="Test">       
            <Grid x:Name="Content" Height="651" Width="941" Background="White">
                ...
                ...
            </Grid>
        </DataTemplate>
    </Page.Resources>
</Page>

...
...

然后我可以使用templateKey=“Test”从上面加载相同代码的页面。但是主要的问题是我想使用页面的第一个声明,而不想使用
等等。我想直接从第一个声明(本文中的第一个代码)加载站点。如何直接从页面创建数据模板?或者是否有其他方法将页面加载到ContentControl中?

没有理由在
ContentControl中使用
页面
Page
UserControl
类的一个子类,它增加了对在
框架中使用的
控件的支持,以支持导航、后台堆栈/历史记录等。您可能应该在XAML和代码隐藏中将
Page
替换为
UserControl
,这样您就可以得到如下结果:

<Page x:Class="ExampleApp.myPage2">
    <Grid x:Name="Content" Height="651" Width="941" Background="White">
        ...
        ...
    </Grid>
</Page>
<UserControl x:Class="ExampleApp.myControl2">
    <Grid x:Name="Content" Height="651" Width="941" Background="White">
        ...
        ...
    </Grid>
</UserControl>

没有理由在
内容控件中使用
页面
Page
UserControl
类的一个子类,它增加了对在
框架中使用的
控件的支持,以支持导航、后台堆栈/历史记录等。您可能应该在XAML和代码隐藏中将
Page
替换为
UserControl
,这样您就可以得到如下结果:

<Page x:Class="ExampleApp.myPage2">
    <Grid x:Name="Content" Height="651" Width="941" Background="White">
        ...
        ...
    </Grid>
</Page>
<UserControl x:Class="ExampleApp.myControl2">
    <Grid x:Name="Content" Height="651" Width="941" Background="White">
        ...
        ...
    </Grid>
</UserControl>

太好了,谢谢你,效果很好。我不认为用户控制是一个很好的解决方案。非常感谢你,它工作得很好。我不认为用户控件是一个很好的解决方案。