views:

367

answers:

1

I have downloaded WPFToolkit, and I am using the DataGrid provided in this package. I am trying to animate a row disappearance when the row is removed, but I don't know how to do it. Does anyone know how it can be done?

A: 

This is the kind of thing that can be tricky in WPF--though your boss will think it should be easy--since WPF is supposed to enable animation and striking visuals. After all, there are all kinds of awesome Silverlight/WPF demos on the web that look great and really sell the tech. Of, course what your boss doesn't know is that those demos were written just to show off the easy, flashy features. Things that are a bit different than standard, however, have a nasty way of being very difficult.

But enough ranting, I'll give you a possible approach, though there may be a far better one:

Let's assume you've bound the DataGrid to some kind of collection, and for sake of argument let's assume its a list of Foo objects, i.e. List<foo> MyFoos. Then you could add a property to the FOO class called BeingDeleted. Then in the template for your DataRowView, trigger on this property to begin a storyboard that animates a fade-out or collapse of that particular row. This is kind of gross, since it implies adding a property to the Foo object that might have nothing to do with it otherwise. You could alternatively create a special wrapper or sub-class of Foo.

PeterAllenWebb
That's how I decided finally to implement this. There were some issues with the bound list synchronization (since the synchronizer should know to ignore the "almost deleted" items), and I also needed to actually delete those items when the animation is over. The final result is kind of messy (everything is tightly coupled), but I guess there is no other solution.
Andy