从GridViewItem中删除填充

时间:2012-05-07 22:46:32

标签: xaml gridview windows-8 windows-runtime winrt-xaml

有人知道从GridViewItem中删除所有填充的方法吗?我正在使用非常小的物品(虽然不是太小,我在下面的图片中夸大了)并且在选择物品时会有一些填充,这使得它非常糟糕并且我想把它取出来。这就是我的意思:

enter image description here

图像的代码是:

<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>

提前致谢!

1 个答案:

答案 0 :(得分:3)

如果你为GridViewItem提取模板 - 你会看到它有一些硬编码值 - 4pt边距,40x40路径等。要解决这个问题 - 你需要修改模板,但你可以硬编码项目尺寸使它们变小 - 只需确保您使用不可见的选择复选标记即可:

    <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>