【问题标题】:DataGridTemplateColumn top margin / paddingDataGridTemplateColumn 上边距/填充
【发布时间】:2012-04-02 05:17:09
【问题描述】:

我的 DataGridTemplateColumn 中有一个 StackPanel。我似乎找不到删除此单元格顶部边距的方法。

这是我正在使用的代码:

        <DataGridTemplateColumn IsReadOnly="True" Header="Description">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel>
                        <StackPanel.Resources>
                            <Style TargetType="{x:Type Label}">
                                <Setter Property="FrameworkElement.Margin" Value="0,0,0,-10" />
                            </Style>
                        </StackPanel.Resources>
                        <Label Content="{Binding Description1}" />
                        <Label Content="{Binding Description2}" />
                    </StackPanel>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>

边距似乎来自 DataGridTemplateColumn 本身而不是 StackPanel,因为只有第一个 Label 在其上方有间距。

【问题讨论】:

    标签: wpf wpfdatagrid margin datagridtemplatecolumn


    【解决方案1】:

    边距实际上是在您的Labels 上,而不是StackPanel。只需删除将下边距设置为负数的标签样式,它就会正常工作。

    一个负边距似乎在对象被渲染后被应用,并且可以使控件移出为它设置的现有边界。在您的情况下,Labels 正在被渲染,然后两者都向下移动 10px

    【讨论】:

      猜你喜欢
      • 2011-04-17
      • 1970-01-01
      • 2012-07-27
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-18
      • 2015-02-15
      相关资源
      最近更新 更多