w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
WPF DataGridRow IsSelected Triggers

The following is a DataGridRow style I use, to get away from the default blue - maybe it provides the answer you seek?

In your DataGrid, set the RowStyle property to this style.

<Style x:Key="BetterHighlightedDataGridRowStyle"
TargetType="sdk:DataGridRow">
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="sdk:DataGridRow">
                <sdk:DataGridFrozenGrid x:Name="Root">
                    <sdk:DataGridFrozenGrid.Resources>
                        <Storyboard x:Key="DetailsVisibleTransition">
                            <DoubleAnimation Duration="00:00:0.1"
Storyboard.TargetProperty="ContentHeight"
Storyboard.TargetName="DetailsPresenter"/>
                        </Storyboard>
                    </sdk:DataGridFrozenGrid.Resources>
                    <sdk:DataGridFrozenGrid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </sdk:DataGridFrozenGrid.ColumnDefinitions>
                    <sdk:DataGridFrozenGrid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </sdk:DataGridFrozenGrid.RowDefinitions>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState
x:Name="NormalAlternatingRow">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="0"
Storyboard.TargetProperty="Opacity"
Storyboard.TargetName="BackgroundRectangle"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <DoubleAnimation Duration="0"
To=".5" Storyboard.TargetProperty="Opacity"
Storyboard.TargetName="BackgroundRectangle"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="NormalSelected">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="1"
Storyboard.TargetProperty="Opacity"
Storyboard.TargetName="BackgroundRectangle"/>
                                    <ColorAnimation Duration="0"
To="#DDE9EE33" Storyboard.TargetProperty="(Fill).Color"
Storyboard.TargetName="BackgroundRectangle"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="MouseOverSelected">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="1"
Storyboard.TargetProperty="Opacity"
Storyboard.TargetName="BackgroundRectangle"/>
                                    <ColorAnimation Duration="0"
To="#E1C8C864" Storyboard.TargetProperty="(Fill).Color"
Storyboard.TargetName="BackgroundRectangle"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="UnfocusedSelected">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="1"
Storyboard.TargetProperty="Opacity"
Storyboard.TargetName="BackgroundRectangle"/>
                                    <ColorAnimation Duration="0"
To="#DDE9EE33" Storyboard.TargetProperty="(Fill).Color"
Storyboard.TargetName="BackgroundRectangle"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="ValidationStates">
                            <VisualState x:Name="Valid"/>
                            <VisualState x:Name="Invalid">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames
Duration="0" Storyboard.TargetProperty="Visibility"
Storyboard.TargetName="BackgroundRectangle">
                                        <DiscreteObjectKeyFrame
KeyTime="0" Value="Collapsed"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <DoubleAnimation Duration="0" To="1"
Storyboard.TargetProperty="Opacity"
Storyboard.TargetName="InvalidVisualElement"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Rectangle x:Name="BackgroundRectangle"
Grid.ColumnSpan="2" Fill="#FFBADDE9" Opacity="0" Grid.RowSpan="2"/>
                    <Rectangle x:Name="InvalidVisualElement"
Grid.ColumnSpan="2" Fill="#FFF7D8DB" Opacity="0" Grid.RowSpan="2"/>
                    <sdk:DataGridRowHeader x:Name="RowHeader"
sdk:DataGridFrozenGrid.IsFrozen="True" Grid.RowSpan="3"/>
                    <sdk:DataGridCellsPresenter x:Name="CellsPresenter"
Grid.Column="1" sdk:DataGridFrozenGrid.IsFrozen="True"/>
                    <sdk:DataGridDetailsPresenter
x:Name="DetailsPresenter" Grid.Column="1" Grid.Row="1"/>
                    <Rectangle x:Name="BottomGridLine"
Grid.ColumnSpan="2" Fill="Black" HorizontalAlignment="Stretch" Height="2"
Grid.Row="2"/>
                </sdk:DataGridFrozenGrid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.