How can I add a ContentDialog to my XAML without getting an err msg about it?

Based on the answer to my question here, which points to this example, I added the following between my ending "Grid" and "Page" tags:

<ContentDialog x:Name="termsOfUseContentDialog"
       PrimaryButtonText="Accept" IsPrimaryButtonEnabled="False"
       CloseButtonText="Cancel"
       Opened="TermsOfUseContentDialog_Opened">
    <ContentDialog.TitleTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Image Source="ms-appx:///Assets/SmallLogo.png" Width="40" Height="40" Margin="10,0"/>
                <TextBlock Text="Terms of use"/>
            </StackPanel>
        </DataTemplate>
    </ContentDialog.TitleTemplate>
    <StackPanel>
        <TextBlock TextWrapping="WrapWholeWords">
    <Run>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor
         congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus
         malesuada libero, sit amet commodo magna eros quis urna.</Run><LineBreak/>
    <Run>Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.</Run><LineBreak/>
    <Run>Pellentesque habitant morbi tristique senectus et netus et malesuada fames
         ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci.</Run><LineBreak/>
    <Run>Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc.
         Mauris eget neque at sem venenatis eleifend. Ut nonummy.</Run>
        </TextBlock>
        <CheckBox x:Name="ConfirmAgeCheckBox" Content="I am over 13 years of age."
          Checked="ConfirmAgeCheckBox_Checked" Unchecked="ConfirmAgeCheckBox_Unchecked"/>
    </StackPanel>
</ContentDialog>

This is a verbatim copy of what is on that page, and is just meant as a starting point, which I would tweak/customize.

It doesn't compile, though. I get these err msgs:

enter image description here

What am I doing wrong?

Upvotes: 0

Views: 108

Answers (2)

The problem was having the ContentDialog between the ending Grid and ending Page. It needs to be within the Grid, not outside of it. IOW, this works:

    . . .
        <ContentDialog x:Name="ContentDialog"
          Title="This is an example"
          PrimaryButtonText="Ok"
          CloseButtonText="Cancel"
          DefaultButton="Primary">
        </ContentDialog>
    </Grid>
</Page>

...but this doesn't:

    . . .
    </Grid>
    <ContentDialog x:Name="ContentDialog"
        Title="This is an example"
        PrimaryButtonText="Ok"
        CloseButtonText="Cancel"
        DefaultButton="Primary">
    </ContentDialog>
</Page>

Upvotes: 0

Roy Li - MSFT
Roy Li - MSFT

Reputation: 8666

Based on the error message, duplication assignment to the Content property of the Page object, this might be caused by adding to more than one panel in the Page.

Generally, the page xaml should looks like this:

<Page
 ...some references here...
 >

<Grid x:Name="FirstGrid">

</Grid></Page>

You could see that only one panel-Grid is set to the content of the Page.

If you add more than one panel to the page like this:

<Page
... some references here...>

<Grid x:Name="FirstGrid">
    
</Grid>
<Grid x:Name="SecondGrid">

</Grid></Page>

Then you will get the error. You need to remove the second grid in the Page and keep only one panel in your Page Content.

Upvotes: 1

Related Questions