我的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,因为只有第一个标签的上方有间距。
发布于 2012-03-17 01:24:23
边距实际上是在你的Labels上,而不是在StackPanel上。只需删除将底部边距设置为负数的标签样式,它就会正常工作。
负边距似乎是在渲染对象之后应用的,并且可以使控件移出为其设置的现有边界。在您的示例中,正在渲染Labels,然后两者都向下移动10px
https://stackoverflow.com/questions/9741063
复制相似问题