Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi people.
Follow my previous post in How do I add new row in datagrid in WPF?[^]
I need to know how may I use animation when a row adds or inserts into this DataGrid?
I mean when I add or insert new row, it opens like curtain... or accordion.
I should remind that the DataGrid source is ObservableCollection.

What I have tried:

I searched internet, but I could not find any idea.
Updated 14-Jan-24 8:26am

I searched CodeProject articles...
Animation using Storyboards in WPF[^]
This may help you to write the code for your own needs.
Share this answer
Sh.H. 15-Jan-24 0:50am
Actually I read that article some months ago. It is not not helping me about this question.
Further to Jo's answer, yes, the article link he has pointed you to does not give you the exact answer that you want however it does show you how to animate. The same principle applies. You need to take that and write the code or use the answer and do the research.

So, use Google Search and look for pointers, like:
* wpf change size animation[^]
* wpf datagrid add row animation[^]
* and so on ...


As I mentioned above, you need to do your research.

My other answer today[^] that you accepted had a link to the DataGrid default template[^]. If you study it, you will see that all of the items are managed in the ItemsControl template. So I did a quick google search: wpf animate add to items panel[^]

Which found this article: WPF ItemsControl with animation on insert – asimplify – aSimplify[^]

Now, this is not for the DataGrid however the same principle applies. Without trying, I would think that you would just need to change the animation direction and the code should work.
Share this answer
Sh.H. 15-Jan-24 4:56am    
Thanks for the answer.
What I need is how the approach, not the exact code.
Look, I know about animations. But what I need to know is that, how can I do this when I have an ObservableCollection ? What trigger I should use in this situation? Because when I use the code "Insert", the ObservableCollection updates immediately, And also the DataGrid updates too. So how can I tell the dataGrid that update via animation? 15-Jan-24 10:17am    
Your other question about binding a ControlTemplate indicates that you use MVVM and therefor use a "PropertyChanged" signal.
Why not using PropertyChanged for starting the animation?
Sh.H. 15-Jan-24 10:19am
How should I tell the DataGrid (with PropertyChanged) that which row is going to add and animation? 15-Jan-24 11:24am    
The PropertyChanged signal is the trigger to start the animation.

You should not tell the DataGrid something about the new row but ask the DataGrid for details about the new row (DataGrid.AddingNewItem event and / or others).

Sh.H. 15-Jan-24 12:01pm
Then the PropertyChanged signal is the trigger to any kind of changing, even if I type new data in a cell, or erase data from a cell. How can I set this to only add new row?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900