2012-03-16 205 views
0

我在我的DataGridTemplateColumn中有一個StackPanel。我似乎無法找到一種方法來刪除此單元格頂部的邊距。DataGridTemplateColumn頂部邊距/填充

下面是我使用的代碼:

 <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的,因爲只有第一個標籤都有它上面的間距。

回答

0

保證金實際上在您的Labels上,而不是StackPanel。只需刪除將底部邊距設置爲負值的標籤樣式,即可正常使用。

消除邊距似乎在渲染對象後應用,並且可以使控件移出爲其設置的現有邊界。在你的情況下,Labels正在渲染,然後兩個正在向下移動10px