将背景颜色 datagrid 更改为 mahapp wpf

Change background color datagrid to mahapp wpf

我尝试用 mahapps 颜色更改数据网格的背景颜色,但我不知道为什么没有更改

<StackPanel>
    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" Margin="20" FontSize="16" Text="Databse"/>

    <DataGrid  AutoGenerateColumns="False" 
               ScrollViewer.CanContentScroll="True"
               MaxHeight ="500" 
               HeadersVisibility="None"
               ScrollViewer.VerticalScrollBarVisibility="Auto"
               ScrollViewer.HorizontalScrollBarVisibility="Auto" 
               Margin="20 0 20 20"
               BorderThickness="0"
               ItemsSource="{Binding Lecturers}">

        <DataGrid.Resources>
            <SolidColorBrush x:Key="MahApps.Brushes.ThemeBackground" Color="#38364E" />
            <SolidColorBrush x:Key="MahApps.Brushes.Text" Color="White"/>
        </DataGrid.Resources>

        <DataGrid.Columns >
            <DataGridTextColumn  Header="Project Name" Binding="{Binding Name}">

            </DataGridTextColumn>
        </DataGrid.Columns>


    </DataGrid>
</StackPanel>

结果总是

定义一个RowStyle:

<DataGrid  AutoGenerateColumns="False" 
               ScrollViewer.CanContentScroll="True"
               MaxHeight ="500" 
               HeadersVisibility="None"
               ScrollViewer.VerticalScrollBarVisibility="Auto"
               ScrollViewer.HorizontalScrollBarVisibility="Auto" 
               Margin="20 0 20 20"
               BorderThickness="0"
               ItemsSource="{Binding Lecturers}">

    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow" BasedOn="{StaticResource MahApps.Styles.DataGridRow}">
            <Setter Property="Background" Value="Red" />
            <Setter Property="Foreground" Value="Yellow" />
        </Style>
    </DataGrid.RowStyle>

    <DataGrid.Resources>
        <SolidColorBrush x:Key="MahApps.Brushes.DataGrid.Selection.Background.MouseOver" Color="Blue" />
    </DataGrid.Resources>

    <DataGrid.Columns >
        <DataGridTextColumn  Header="Project Name" Binding="{Binding Name}" />
    </DataGrid.Columns>

</DataGrid>