Harold Finch
Harold Finch

Reputation: 586

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?

Upvotes: 2

Views: 3832

Answers (1)

punker76
punker76

Reputation: 14611

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>

enter image description here

Upvotes: 3

Related Questions