从GridViewItem删除填充 [英] Remove padding from GridViewItem
问题描述
有人知道从GridViewItem删除所有填充的方法吗?我使用的物品很小(不过不太小,在下面的图片中我夸大了),选择物品时会有一些填充,这会使它变得非常不好,我想将其取出.这就是我的意思:
Does anybody know a way to remove all the padding from GridViewItem? I'm using very small items (not too small though, I exaggerated in the picture below) and there's some padding when selecting the items which makes it good really bad and I'd like to take it out. This is what I mean:
图像的代码是这样的:
<GridView Margin="120,80,0,0"
SelectionMode="Multiple">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel
Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</GridView.ItemContainerStyle>
<Rectangle Height="10" Width="10" Fill="Red" />
<Rectangle Height="10" Width="10" Fill="Orange" />
<Rectangle Height="10" Width="10" Fill="Blue" />
<Rectangle Height="10" Width="10" Fill="Green" />
<Rectangle Height="10" Width="10" Fill="Yellow" />
</GridView>
提前谢谢!
推荐答案
如果您为GridViewItem提取模板-您会看到它具有一些硬编码的值-4pt边距,40x40路径等.将需要修改模板,但是您可以对项目尺寸进行硬编码以使其更小-只需确保您可以使用不可见的选择复选标记就可以:
If you extract the template for a GridViewItem - you'll see that it has some hardcoded values - 4pt Margins, 40x40 paths etc. To go around that - you would need to modify the template, but you can hard-code the item dimensions to make them smaller - just make sure you are OK with invisible selection checkmarks:
<GridView
Margin="120,80,0,0"
SelectionMode="Multiple">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel
Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemContainerStyle>
<Style
TargetType="GridViewItem">
<Setter
Property="HorizontalAlignment"
Value="Center" />
<Setter
Property="VerticalAlignment"
Value="Center" />
<Setter
Property="Width"
Value="20" />
<Setter
Property="Height"
Value="20" />
<Setter
Property="Padding"
Value="0" />
<Setter
Property="Margin"
Value="0" />
</Style>
</GridView.ItemContainerStyle>
<Rectangle
Height="10"
Width="10"
Fill="Red" />
<Rectangle
Height="10"
Width="10"
Fill="Orange" />
<Rectangle
Height="10"
Width="10"
Fill="Blue" />
<Rectangle
Height="10"
Width="10"
Fill="Green" />
<Rectangle
Height="10"
Width="10"
Fill="Yellow" />
</GridView>
这篇关于从GridViewItem删除填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!