WPF数据网格单元格背景颜色未完全填充

4
背景颜色在单元格和网格线之间留下了小空间。我该如何使其完全填充?我尝试过将padding/margin设置为0。
截图: http://s21.postimg.org/xqe4mt4dv/Data_Grid_Cell_Background.png 有没有样式专家可以帮忙?
 <DataGrid ItemsSource="{Binding}" >
     <DataGrid.CellStyle>
        <Style TargetType="DataGridCell">
           <Setter Property="Background" Value="Red"/>
        </Style>
     </DataGrid.CellStyle>
  </DataGrid>


  Data = new Dictionary<int,string>();         
     for (int i = 0; i < 5; i++)
        Data.Add(i, "Text");
  DataContext = Data;
1个回答

4

这很简单。将 BorderThickness 设置为 0

<DataGrid ItemsSource="{Binding}" >
    <DataGrid.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="Background" Value="Red"/>
            <Setter Property="BorderThickness" Value="0" />
        </Style>
    </DataGrid.CellStyle>
</DataGrid>

下次当你想知道为什么事物看起来是这个样子时,尝试使用Snoop。检查控件和面板以及它们的属性(在这种情况下,可能是Margin、Padding或BorderThickness),以查看您需要从XAML进行哪些调整。


这将使选择边框消失,但对于真正的强迫症患者,您可以为“IsSelected”的Style添加一个Trigger并将边框厚度重置为1。 - Tekito

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接