【问题标题】:C# WPF datagrid - spacing on autowith columnsC# WPF 数据网格 - 自动列间距
【发布时间】:2016-02-02 02:12:21
【问题描述】:

我有一个带有列的数据网格。每列都有自动宽度(取决于内容)。我的问题是我想要每列之间的间距(填充?)。

我尝试使用以下代码实现此目的:

 <Style TargetType="{x:Type DataGridCell}">
            <Setter Property="Padding" Value="0 0 20 0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridCell}">
                        <Border Padding="{TemplateBinding Padding}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                            <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

它基本上可以工作,但如果我选择一个单元格,20px(填充)不会被选中(它只是一个设计问题)。

它看起来并不漂亮。有任何想法吗?

【问题讨论】:

  • 恕我直言,这很正常,这是我在未更改模板的 Datagrid 上观察到的:有一些填充没有被选中。问候

标签: c# wpf datagrid spacing


【解决方案1】:

尝试为每一列添加样式并在那里定义填充。类似Style="{StaticResource InfoNameTextBlock}" 在你保持风格的课堂上

<Style TargetType="yourType" x:Key="InfoNameTextBlock">
    <Setter Property="Padding" Value="5,0"/>
</Style>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 2017-06-16
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多