This week I ran into a very strange behavior with the Silverlight DataGrid.
I added new items via an ObservableCollection to a set of existing items which are already bound to a standard DataGrid. If the new items are inserted on a lower index than the currently displayed range of items the result of the DataGridRow.GetIndex is not correct.
This has several side effects:
- The hover effect does not work correct
- Some rows lose the entire hover behavior
- The alternating row background is set wrong
- DataGridRow.GetIndex returns old index
- Scrollbar jumps sometimes during thumb-track (I was not able to isolate this so far…)
It’s hard to explain all these in detail; therefore it created a short video.
The remove notification from the observable collection works perfect (see last section in the video). All gets updated including the result of GetIndex and the AlternatingRowBackground for each row is correct.
I guess this is a misbehavior in the DataGrid, because of the fact that the Remove operation is working correctly.
First of all: fully rebind the DataGrid is not a solution for me, because the DataGrid is updating itself every few minute (remove/insert/add rows) from a service.
Can someone from the Silverlight team verify my assumption?
Silverlight Version is 3.0.40818.0.
Source code and Demo.
Thanks in advance,
Beat Kiener



If I use the build-in Datagrid control instead of EvdDataGrid then the hover, altrenative row background are working fine. I think it happens only for EvdDataGrid .
By: Michael Sync on September 21, 2009
at 3:59 am
The Microsoft Silverlight Team confirmed it as a bug. See the last comment in the following thread: http://forums.silverlight.net/forums/p/129843/290689.aspx#290689
It did not any further work in this problem. Silverlight 4 Beta 1 will be shipped soon, I think tomorrow at the PDC09 (www.microsoftpdc.com). Hopfully the bug will be fiexed in this version.
By: beatkiener on November 17, 2009
at 3:14 pm
Hi Michael,
Unfortunately not. I changed it to the build-in DataGrid and the same misbehavior happens. The only reason for EvdDataGrid subclass is to the get an instance of the rowpresenter in the OnApplyTemplate override.
Could you post me your solution?
Best regards,
Beat
By: beatkiener on September 21, 2009
at 5:56 am
This is the code of my datagrid subclass
public class EvdDataGrid : DataGrid { internal DataGridRowsPresenter rowPresenter; public override void OnApplyTemplate() { base.OnApplyTemplate(); // get row presenter this.rowPresenter = GetTemplateChild("RowsPresenter") as DataGridRowsPresenter; } internal int[] GetRowsInView() { /* ***************************************************************************************** * Returns wrong indexes if items where added prior to the top row visible in the grid ******************************************************************************************/ var query = from DataGridRow row in this.rowPresenter.Children where row.Visibility == Visibility.Visible orderby row.GetIndex() select row.GetIndex(); return query.ToArray(); } }By: beatkiener on September 21, 2009
at 5:57 am
I am having a similar issue. All of the symptoms from your video present themselves. However, I am not adding rows to my grid. All of my rows are added in one shot. However, I am swapping out each object in my observable collection for an updated version of that object as data gets loaded. I am not sure if that helps. The issue is defintiely in the DataGridRowPresenter, and simply manifests itself in the DataGrid because it is using the presenter. Have you gotten any further with this? Please let me know if you have found a workaround or if you hear anything from the Silverlight development staff.
Thanks,
Ryan
By: Ryan Scanlon on November 17, 2009
at 2:06 pm
I have similar issue. In this case empty rows appear in top of DataGrid if number of DataGrids are instantiated. I created video to show this and put it to
http://cid-69f11148404c9c0e.skydrive.live.com/self.aspx/.Public/emptyrows.avi
How to fix this ?
This was also discussed in http://forums.silverlight.net/forums/t/181553.aspx
By: Andrus on May 13, 2010
at 7:40 pm
Microsoft confirmed that this is a bug. See the last past in this thread:
http://forums.silverlight.net/forums/p/129843/290431.aspx
Currently I don’t know if the bug is fixed with Silverlight 4.
By: beatkiener on May 14, 2010
at 7:14 am
Empty row isse is present in SL4. This was also discussed in http://forums.silverlight.net/forums/p/185272/426310.aspx#426310
By: Andrus on June 9, 2010
at 5:58 pm