Load a Page into a ContentControl

后端 未结 1 1866
[愿得一人]
[愿得一人] 2021-01-16 17:32

I have a ContentControl where I want to load the page myPage2. My XAML Codefrom this page looks like this:



        
相关标签:
1条回答
  • 2021-01-16 17:58

    There is no reason to use a Page within a ContentControl. A Page is a subclass of the UserControl class that adds support for being used within a Frame control to support navigation, back stack/history, etc. You should probably replace Page with UserControl in XAML and code behind, so you would end up with something like this:

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

    You can put the UserControl itself in a DataTemplate if you want to use it as a DataTemplate in a ContentControl:

    <ContentControl
        xmlns:controls="using:ExampleApp">
        <ContentControl.Resources>
            <DataTemplate
                x:Key="Test">
                <controls:myControl2 />
            </DataTemplate>
        </ContentControl.Resources>
    </ContentControl>
    
    0 讨论(0)
提交回复
热议问题