1
votes

WPF data grid

How to set wpf datagrid background color? There are only several rows in datagrid, and there is empty space below rows. How to set color of this gray space (see image above)

Here is my code:

 <DataGrid x:Name="dataGrid" 
                  ItemsSource="{Binding ReferentViewModels }"                   
                  SelectedItem="{Binding SelectedReferentViewModel}"
                  VerticalAlignment="Top" 
                  AutoGenerateColumns="False"
                  IsReadOnly="true"
                  SelectionMode="Single" 
                  SelectionUnit="FullRow" 
                  Margin="0,0,0,0"
                  Height="NaN"                     
                  Background="Aqua"
                  >
        <DataGrid.Columns>
            <DataGridTextColumn Header="Naziv" MinWidth="200" Width="0.25" Binding="{Binding Name}"/>
            <DataGridTextColumn Header="Opis" MinWidth="100" Width="*"  Binding="{Binding Description}"/>
        </DataGrid.Columns>

    </DataGrid>

Also, simple style is applied:

    <Style TargetType="{x:Type DataGrid}">
    <Setter Property="AlternatingRowBackground" Value="Azure" />
    <Setter Property="HeadersVisibility" Value="All" />
    <Setter Property="RowHeaderWidth" Value="20" />
    <Setter Property="CanUserResizeRows" Value="False" />
</Style>

I tried with background property, but it's not working.

1
What's behind the DataGrid? It's probably the colour of this panel you are seeing since you have set the VerticalAlignment property of the DataGrid to Top. Otherwise setting Background property should work. - mm8
You are right. Behind the datagrid is Grid panel, and it's background is set to gray. Thank you. - Klik Kliković

1 Answers

1
votes

What's behind the DataGrid? It's probably the colour of this panel you are seeing since you have set the VerticalAlignment property of the DataGrid to Top. Otherwise setting Background property should work.