"Content" 属性 被定义了不止一次

The "Content" property is defined more than once

我正在尝试创建一个 gridview,我可以在其中显示列表中的所有用户,而 VS return给我以下错误:

XLS050: The "Content" property is defined more than once

XAML代码:

<Page
x:Class="AppTeste.UsersGrid"
Background="{ThemeResource SystemAltMediumHighColor}">
<Page.Resources>
    <DataTemplate x:Key ="ImageTextTemplate"/>
</Page.Resources>

<GridView
x:Name="ContentGridView2"
ItemsSource="{x:Bind Users}"
ItemTemplate="{StaticResource ImageTextTemplate}"
IsItemClickEnabled="True"
CanDragItems="True"
AllowDrop="False"
CanReorderItems="False"
SelectionMode="Single"
FlowDirection="LeftToRight"/>

    <Grid AutomationProperties.Name = '{x:Bind Name}' Width = '280'>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width = 'Auto'/>
            <ColumnDefinition Width = '*'/>
        </Grid.ColumnDefinitions>
        <!--<Image Source = '' Height = '100' Stretch = 'Fill' VerticalAlignment = 'Top'/>-->
        <StackPanel Grid.Column = '1' Margin = '8,0,0,8'>
            <TextBlock Text = '{x:Bind  Name}' Style = '{ThemeResource SubtitleTextBlockStyle}' Margin = '0,0,0,8'/>
            <StackPanel Orientation = 'Horizontal'>
                <TextBlock Text = '{x:Bind Email}' Style = '{ThemeResource CaptionTextBlockStyle}'/>
                <TextBlock Text = ' Views ' Style = '{ThemeResource CaptionTextBlockStyle}'/>
            </StackPanel>
            <StackPanel Orientation = 'Horizontal'>
                <TextBlock Text = '{x:Bind  ID}' Style = '{ThemeResource CaptionTextBlockStyle}'/>
                <TextBlock Text = 'ID' Style = '{ThemeResource CaptionTextBlockStyle}'/>
            </StackPanel>
        </StackPanel>
    </Grid>

C#Class:

 public sealed partial class UsersGrid : Page
{

    public List<User> Users { get; set; }

    public UsersGrid()
    {
        Users = new List<User>();

        for (int i = 0; i < 20; i++)
        {
            Users.Add(new User() { ID = i, Name = $"Utilizador{i}", Email = $"Utillizador{i}@servidor.pt" });
        }


        this.InitializeComponent();
    }
}

我不知道自己做错了什么,因为我使用的是 Microsoft XAML Control Gallery 中几乎未经编辑的 GridView 模板,即使它完全未经编辑,它也会 return 我同样的错误。

问题是 Page 只能有一个元素作为其内容。在这种情况下,您有两个 - GridViewGrid.

要解决此问题,请将两者包裹在另一个布局元素中,例如 Grid。通常,确保 Page 只有一个 child .

更新:在 re-reading 代码之后,您似乎实际上希望 Grid 成为 [=12] 的 ItemTemplate =].在这种情况下,它将如下所示(您需要将 YOURMODELTYPE 替换为您的实际项目类型):

<GridView
x:Name="ContentGridView2"
ItemsSource="{x:Bind Users}"
ItemTemplate="{StaticResource ImageTextTemplate}"
IsItemClickEnabled="True"
CanDragItems="True"
AllowDrop="False"
CanReorderItems="False"
SelectionMode="Single"
FlowDirection="LeftToRight">
   <GridView.ItemTemplate>
    <DataTemplate x:DataType="YOURMODELTYPE">
    <Grid AutomationProperties.Name = '{x:Bind Name}' Width = '280'>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width = 'Auto'/>
            <ColumnDefinition Width = '*'/>
        </Grid.ColumnDefinitions>
        <!--<Image Source = '' Height = '100' Stretch = 'Fill' VerticalAlignment = 'Top'/>-->
        <StackPanel Grid.Column = '1' Margin = '8,0,0,8'>
            <TextBlock Text = '{x:Bind  Name}' Style = '{ThemeResource SubtitleTextBlockStyle}' Margin = '0,0,0,8'/>
            <StackPanel Orientation = 'Horizontal'>
                <TextBlock Text = '{x:Bind Email}' Style = '{ThemeResource CaptionTextBlockStyle}'/>
                <TextBlock Text = ' Views ' Style = '{ThemeResource CaptionTextBlockStyle}'/>
            </StackPanel>
            <StackPanel Orientation = 'Horizontal'>
                <TextBlock Text = '{x:Bind  ID}' Style = '{ThemeResource CaptionTextBlockStyle}'/>
                <TextBlock Text = 'ID' Style = '{ThemeResource CaptionTextBlockStyle}'/>
            </StackPanel>
        </StackPanel>
    </Grid>   
   </DataTemplate>
  <GridView.ItemTemplate>
</GridView>