简体   繁体   English

“内容”属性被多次定义

[英]The "Content" property is defined more than once

I'm trying to create a gridview where I can show all the users in a List and VS is returning me the following error:我正在尝试创建一个 gridview ,我可以在其中显示列表中的所有用户,并且 VS 向我返回以下错误:

XLS050: The "Content" property is defined more than once XLS050:多次定义“内容”属性

XAML Code: 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: 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();
    }
}

I can't figure out what I'm doing wrong since I'm using almost unedited GridView template from Microsoft XAML Control Gallery and even if it was fully unedited it would return me the same error.我无法弄清楚我做错了什么,因为我使用的是来自 Microsoft XAML Control Gallery 的几乎未经编辑的 GridView 模板,即使它完全未经编辑,它也会返回相同的错误。

The problem is that the Page can have only a single element as its content.问题是Page只能有一个元素作为其内容。 In this case you have two - the GridView and Grid .在这种情况下,您有两个 - GridViewGrid

To fix this, wrap the two inside another layout element like Grid .要解决此问题,请将两者包装在另一个布局元素中,例如Grid In general, ensure the Page has just a single child.一般来说,确保Page只有一个孩子。

Update : After re-reading the code, it seems you actually want the Grid to be the ItemTemplate of the GridView .更新:重新阅读代码后,您似乎实际上希望Grid成为GridViewItemTemplate In such case it would look as follows (you need to replace YOURMODELTYPE with your actual item type):在这种情况下,它将如下所示(您需要将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>

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

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