简体   繁体   中英

How to change selected row color in DataGrid Mahapp

I'm trying to change the color of the selected row but can't result. I've tryed with this:

<DataGrid Style="{StaticResource AzureDataGrid}">

But the only change that I can see is the first column colored by azure. When I select a row, this becomes white and I can't see the values on the row selected. I'm new for this framework theme wpf and the documentation isn't accurate. Can someone help me?

Changing the selected row brush is now possible with the latest Alpha version of MahApps.Metro (1.1.3.x or later 1.2.0)

Here is the example from the main demo

<DataGrid x:Name="MetroDataGrid"
            Grid.Column="1"
            Grid.Row="1"
            RenderOptions.ClearTypeHint="Enabled"
            TextOptions.TextFormattingMode="Display"
            HeadersVisibility="All"
            Margin="5"
            SelectionUnit="FullRow"
            ItemsSource="{Binding Path=Albums}"
            AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridCheckBoxColumn ElementStyle="{DynamicResource MetroDataGridCheckBox}"
                                EditingElementStyle="{DynamicResource MetroDataGridCheckBox}"
                                Header="IsSelected"
                                Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsSelected, Mode=OneWay}" />
        <DataGridTextColumn Header="Title"
                            Binding="{Binding Title}" />
        <DataGridTextColumn Header="Artist"
                            Binding="{Binding Artist.Name}" />
        <DataGridTextColumn Header="Genre"
                            Binding="{Binding Genre.Name}" />
        <controls:DataGridNumericUpDownColumn Header="Price"
                                                Binding="{Binding Price}"
                                                StringFormat="C"
                                                Minimum="0" />
    </DataGrid.Columns>
    <DataGrid.Style>
        <Style BasedOn="{StaticResource MetroDataGrid}"
                TargetType="{x:Type DataGrid}">
            <Setter Property="AlternatingRowBackground"
                    Value="{DynamicResource GrayBrush10}" />
        </Style>
    </DataGrid.Style>
    <DataGrid.RowStyle>
        <Style BasedOn="{StaticResource MetroDataGridRow}"
                TargetType="{x:Type DataGridRow}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Price, Mode=OneWay, Converter={StaticResource AlbumPriceIsTooMuchConverter}}"
                                Value="True">
                    <Setter Property="Background"
                            Value="#FF8B8B" />
                    <Setter Property="Foreground"
                            Value="Red" />
                </DataTrigger>
                <!-- IsMouseOver -->
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Price, Mode=OneWay, Converter={StaticResource AlbumPriceIsTooMuchConverter}}"
                                    Value="True" />
                        <Condition Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource Self}}"
                                    Value="true" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Background"
                            Value="#FFBDBD" />
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
    <DataGrid.RowValidationRules>
        <ValueConverter:AlbumPriceIsReallyTooMuchValidation ValidatesOnTargetUpdated="True"
                                                            ValidationStep="CommittedValue" />
        <ValueConverter:AlbumPriceIsReallyTooMuchValidation ValidatesOnTargetUpdated="True"
                                                            ValidationStep="UpdatedValue" />
    </DataGrid.RowValidationRules>
</DataGrid>

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM