views:

704

answers:

2

I have a Silverlight DataGrid that contains a single template column which displays a user control. The user control has a progress bar to represent processing and when the processing is complete an animation hides the progress bar and shows a finished label.

There are two instances in which the datagrid seems not to redraw itself:

First, when a user does a lot of scrolling then the datagrid will start by redrawing the animation when the usercontrol comes into view and will finally reach a point where it doesn't redraw anything.

Second, there is a click event in the usercontrol that displays a popup. When the popup is closed then again the usercontrol fails to redraw itself properly.

Any ideas as to why this behavior occurs and ways around it?

A: 

You have to understand that a DataGrid does not have one instance of your control for every row in the grid. The data source could have millions of rows, while the grid doesn't need more instances of your control than will fit on the screen. This means that when you scroll, for instance, it doesn't reveal instances of your control previously invisible; it just assigns the currently-visible controls whatever values are needed to make the correct display for the current scroll position.

I don't know if there is a workaround.

Gabe
+1  A: 

The previous answer is correct. I have found that sometimes you have to properly handle the Loading_Row and Unloading_Row events if you want any of your controls to behave properly. In my cases having the controls properties actually bound to an object to work best. If you try to rely on animations and visibility and the like you will see strange behavior but if you bind the progressbar to an object that is maintaining the progress for each item behind the scenes then every time that row is shown it will rebind and redraw.

Midnit
Have you had strange behavior when users click inside the grid as well? Clicking seems to also invoke a "repaint" which can force a redraw of animation too.
David in Dakota