[英]uwp list view item never covers available horizontal space
我有一个水平的listview,并且设置了各种拉伸属性,但是listview项保留在中心,在实际数据模板网格的左右两侧留有一些空间。 我也注意到垂直列表视图上的相同行为。
正如您在上方图像中所看到的那样,该间隙在那里,并且由listviewitem用来显示突出显示。 我想消除这一差距。
码
<ListView Style="{StaticResource PivotListViewStyle}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Style="{StaticResource TileGridStyle}" >
<-- other irrelivant xaml-->
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
样式
<Style TargetType="ListView" x:Key="StretchListviewStyle">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
</Style>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ListView" x:Key="PivotListViewStyle" BasedOn="{StaticResource StretchListviewStyle}">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="TileGridStretchStyle" TargetType="Grid">
<Setter Property="Height" Value="{StaticResource MainItemHeight}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Margin" Value="2"/>
<Setter Property="Padding" Value="4"/>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{ThemeResource SystemAccentColor}"/>
</Setter.Value>
</Setter>
</Style>
<x:Double x:Key="MainItemHeight">114</x:Double>
<Style x:Key="TileGridStyle" TargetType="Grid" BasedOn="{StaticResource TileGridStretchStyle}">
<Setter Property="Width" Value="{StaticResource MainItemHeight}"/>
</Style>
摄制
重现该问题,您可以看到这个最小的项目: https : //github.com/touseefbsb/ListViewItemSpacingBug
这是因为ListViewItem
的默认Padding
为12,0,12,0
。
用另一个值覆盖填充:
<Style TargetType="ListView" x:Key="StretchListviewStyle">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Padding" Value="1"/>
</Style>
</Setter.Value>
</Setter>
</Style>
这就是您得到的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.