Reputation: 263
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:
XLS050: The "Content" property is defined more than once
XAML Code:
<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();
}
}
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.
Upvotes: 0
Views: 383
Reputation: 39092
The problem is that the Page
can have only a single element as its content. In this case you have two - the GridView
and Grid
.
To fix this, wrap the two inside another layout element like Grid
. In general, ensure the Page
has just a single child 👍 .
Update: After re-reading the code, it seems you actually want the Grid
to be the ItemTemplate
of the GridView
. In such case it would look as follows (you need to replace YOURMODELTYPE
with your actual item type):
<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>
Upvotes: 3