【问题标题】:Remove padding from GridViewItem从 GridViewItem 中删除填充
【发布时间】:2012-05-08 12:14:44
【问题描述】:

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

图片的代码是这样的:

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

提前致谢!

【问题讨论】:

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


    【解决方案1】:

    如果您提取 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>
    

    【讨论】:

    • 我不想对尺寸进行硬编码,因为这样会裁剪较大的项目。我将尝试使用 Blend 提取模板,让您知道它是如何进行的。谢谢!
    猜你喜欢
    • 2012-12-27
    • 2021-10-07
    • 2020-11-08
    • 2016-01-09
    • 1970-01-01
    • 2023-04-04
    • 2020-12-01
    • 2018-08-03
    • 2012-07-23
    相关资源
    最近更新 更多