WPF DataGrid - Highlight new rows when inserted into datagrid

I have a datagrid associated with an ObservableCollection, and what I would like to do is highlight the new rows when they are added to the datagrid (i.e. when a new object is inserted into the ObservableCollection). I would like to highlight the lines when they are inserted, first changing the background color, but after that the color gradually fades. I tried various methods to make it work, but nothing works properly.

Method 1: I have an event trigger that fires when a column loads. It fires when an element loads, but it seems to fire almost by accident on other old lines (lines on which it was already run once when the line was new).

<DataGridHyperlinkColumn x:Name="OrderID" Binding="{Binding OrderNumber}" Header="Order" SortMemberPath="ciOrderId">
    <DataGridHyperlinkColumn.ElementStyle>                                
        <Style TargetType="TextBlock">
            <Setter Property="Background" Value="Transparent"/>
            <EventSetter Event="Hyperlink.Click" Handler="OrderNumber_Click" />
            <Style.Triggers>
                <EventTrigger RoutedEvent="Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation 
                                            Storyboard.TargetProperty="(TextBlock.Background).(SolidColorBrush.Color)" 
                                            Duration="00:00:03" 
                                            From="Red" To="Transparent" />
                        </Storyboard>                                                
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>

2: bool , true, ObservableCollection. , , . , , , . , , false ( Completed eventboard, DataTrigger ).

<DataTrigger Binding="{Binding isNew}" Value="True">
    <DataTrigger.EnterActions>
        <BeginStoryboard>
            <Storyboard>
                <ColorAnimation
                    Storyboard.TargetProperty="(TextBlock.Background).(SolidColorBrush.Color)" 
                    Duration="00:00:03" 
                    From="Red" To="{x:Null}" FillBehavior="Stop"/>
            </Storyboard>
        </BeginStoryboard>
    </DataTrigger.EnterActions>
</DataTrigger>

3: , . XAML , , . , INotifyPropertyChanged, , , .

, , , , , , - .

+5
1

-, . 1 , , , , . ( : DataGrid WPF Toolkit).

, datagrid:

VirtualizingStackPanel.VirtualizationMode="Standard"

, 1:

<DataGridHyperlinkColumn x:Name="OrderID" Binding="{Binding OrderNumber}" 
        Header="Order" SortMemberPath="ciOrderId">
    <DataGridHyperlinkColumn.ElementStyle>                                
        <Style TargetType="TextBlock">
            <Setter Property="Background" Value="Transparent"/>
            <EventSetter Event="Hyperlink.Click" Handler="OrderNumber_Click" />
            <Style.Triggers>
                <EventTrigger RoutedEvent="Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation 
                                Storyboard.TargetProperty="(TextBlock.Background).(SolidColorBrush.Color)" 
                                Duration="00:00:03" 
                                From="Red" To="Transparent" />
                        </Storyboard>                                                
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>

, datagrid. !

+6

All Articles