Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7063647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:44:17+00:00 2026-05-28T04:44:17+00:00

I have a datagrid bound to an ObservableCollection, and what I’d like to do

  • 0

I have a datagrid bound to an ObservableCollection, and what I’d like to do is highlight new rows when they are added to the datagrid (i.e. when a new object is inserted into the ObservableCollection). I’d like to highlight the rows when they are inserted by changing the background colour initially, but then having the colour fade back to normal over time. I’ve tried a variety of different methods to get it to work but nothing quite works properly.

Method 1: I have an event trigger that fires when the column loads. It does fire when the element loads, but it seems to fire almost randomly on other old rows as well (rows on which it already fired once when the row 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>

Method 2: I made a bool in the view model that is set to true when the new item is added to the ObservableCollection. I then check this value in a trigger and if it is true I fire the storyboard. I can’t get this to work properly though, and the application keeps erroring out when I run it. Also, I can’t figure out a way to set this value to false once the storyboard has run (I can’t use the storyboard’s Completed event because the DataTrigger is in a style).

<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>

Method 3: I tried setting a timestamp field in the view model when the new item is added to the observable collection. Then in XAML I want to be able to compare that timestamp to the current time, and if it matches then I will fire the event. I even have another field that contains the current time and is automatically updated by INotifyPropertyChanged, but I can’t seem to figure out a way to compare the timestamp of the new row to the field containing the current time.

I feel like there must be a solution to this, but after spending a frustrating day trying to figure it out I’m hoping someone out there will be able to shed some light.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:44:18+00:00Added an answer on May 28, 2026 at 4:44 am

    While working on another issue I found something that helped me solve this problem. The solution in Method 1 is very close, it was just a matter of solving the problem of the seemingly random other rows also being highlighted at seemingly random times. The problem was container recycling (more information in this question: WPF Toolkit DataGrid Checkbox Issues).

    Anyways, all I had to do was add the following tag to my datagrid:

    VirtualizingStackPanel.VirtualizationMode="Standard"
    

    And then I used the same trigger as in method 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>
    

    Now I’m able to highlight new rows as they are inserted into my datagrid. Very useful!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagrid that's bound to an observablecollection object. The collection may be
I have an Observable Collection bound to Datagrid. ObservableCollection<Person> PersonOC = new ObservableCollection<Person>(); public
I have a simple Silverlight 5 datagrid bound to a ObservableCollection of objects: <sdk:DataGrid
I have a WPF DataGrid bound to ObservableCollection . Each item in my collection
I have a DataGrid bound to a ViewModel's property of type ObservableCollection. Inside DataGrid
I have a datagrid that is bound to a observableCollection of Employees The user
I have an ObservableCollection bound to a WPFToolkit DataGrid in an MVVM pattern. Every
I have a View that displays a DataGrid which is bound to an ObservableCollection
I have an issue with a datagrid inserting/updating rows twice. The datagrid is bound
I have a WPF Toolkit DataGrid bound to an ObservableCollection of Car in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.