我在页面上有以下GridView:
<GridView Background="Black">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.Items>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Hello"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="there"/>
</GridView.Items>
</GridView>
这会在左上象限中将“Hello”和“there”呈现在彼此的顶部。我原本希望在左上象限中找到“Hello”,在右下象限中找到“there”。
我错过了什么?
答案 0 :(得分:3)
框架将自动创建一个GridViewItem以包含GridView中的每个项目,除非您明确创建一个。因此,对所包含项目设置Grid.Row
或Grid.Column
将无效。试试这个:
<GridView Background="Black">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.Items>
<GridViewItem Grid.Row="0" Grid.Column="0">
<TextBlock Text="Hello"/>
</GridViewItem>
<GridViewItem Grid.Row="1" Grid.Column="1">
<TextBlock Text="there"/>
</GridViewItem>
</GridView.Items>
</GridView>