简体   繁体   English

如何在没有收到错误消息的情况下将 ContentDialog 添加到我的 XAML 中?

[英]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:根据我的问题here的答案,它指向这个例子,我在结尾的“Grid”和“Page”标签之间添加了以下内容:

<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:我收到这些错误消息:

在此处输入图像描述

What am I doing wrong?我究竟做错了什么?

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.根据错误消息, duplication assignment to the Content property of the Page object ,这可能是由于在页面中添加了多个面板。

Generally, the page xaml should looks like this:通常,页面 xaml 应如下所示:

<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.您需要删除页面中的第二个网格,并在页面内容中只保留一个面板。

The problem was having the ContentDialog between the ending Grid and ending Page.问题是在结束网格和结束页面之间有 ContentDialog。 It needs to be within the Grid, not outside of it.它需要在网格内,而不是在网格外。 IOW, this works: IOW,这有效:

    . . .
        <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM