[英]Grid view Item does not take all width availabel UWP Xaml
I wan't to display a grid view list item but I don't know why the gridview (in purple) take all the place I wan't but the grid elements does not take all the width evailable they wrap the content, what I'm missing ? 我不想显示网格视图列表项,但是我不知道为什么网格视图(紫色)占据了我所不希望的所有位置,但是网格元素却没有占据它们包裹内容的所有宽度,我失踪了吗?
<GridView
Background="Purple"
Grid.Row="1"
Margin="20,20,20,0"
ItemsSource="{Binding MyItems}"
Style="{StaticResource GridViewStyle}"
SelectionMode="Multiple"
HorizontalContentAlignment="Stretch">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="White"
BorderThickness="1"
BorderBrush="Gray">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Stretch">
<TextBlock Text="{Binding Name, Mode=OneWay}"/>
<TextBlock Text="{Binding Creator, Mode=OneWay}"/> </StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="Margin" Value="0,0,0,20"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</GridView.ItemContainerStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center"
MaximumRowsOrColumns="1"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
Here is the render : 这是渲染:
If you want the items to stack like this, you should be using a ListView
instead. 如果要这样堆叠项目,则应改用ListView
。 All you have to do is to remove the whole <GridView.ItemsPanel>...</GridView.ItemsPanel>
code, change the GridView
to ListView
and TargetType="GridViewItem"
to TargetType="ListViewItem"
. 您要做的就是删除整个<GridView.ItemsPanel>...</GridView.ItemsPanel>
代码,将GridView
更改为ListView
,将TargetType="GridViewItem"
更改为TargetType="ListViewItem"
。
It looks like you want a single-column GridView. 看起来您想要一个单列GridView。 Try to use a ListView instead, and remove the custom ItemsPanelTemplate from your code. 尝试改用ListView,然后从代码中删除自定义ItemsPanelTemplate。 In the ListView items will use all the width available. 在ListView中,项目将使用所有可用宽度。
Alternatively set the HorizontalAlignment="Stretch" in your ItemsWrapGrid. 或者,在ItemsWrapGrid中设置HorizontalAlignment =“ Stretch”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.