Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf datagrid cell background color doesnt fill completely

Tags:

wpf

datagrid

The background color leaves tiny space between the cell & grid lines. How could I make it fill completely? I have tried tried padding/margin = 0.

Screenshot: http://s21.postimg.org/xqe4mt4dv/Data_Grid_Cell_Background.png

Any styling experts out there?

 <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;
like image 703
Dev Avatar asked Oct 24 '25 03:10

Dev


1 Answers

This one's easy. Set the BorderThickness to 0:

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

Next time you wanna find out why things look how they look, give Snoop a try. Check the controls and panels, and their properties (in this case, it could be either Margin, Padding or BorderThickness), to see what you have to tweak from XAML.

like image 98
almulo Avatar answered Oct 27 '25 00:10

almulo