Reputation: 1931
Silverlight DataGrid
scrolling, DataGrid
fires a RowLoading
event. How to stop the scroll event from firing RowLoadingRow
event?
Upvotes: 1
Views: 575
Reputation: 21
I hope this helps, this runs in silverlight.
void grid_LoadingRow(object sender, DataGridRowEventArgs e)
{
YourViewModel vm = this.DataContext as YourViewModel;
//prevent the LoadingRow on Scroll
if (vm.NumRowsLoaded >= vm.NumRowsTotal)
return;
vm.NumRowsLoaded += 1;
RowObject c = e.Row.DataContext as RowObject;
if (c != null)
{
//Your styling options
}
}
You must control NumRowsLoaded and NumRowsTotal in your ViewModel when charge your data.
Upvotes: 2
Reputation: 15941
The RowLoading event is fired because rows are virtualized. With virtualization, rows are created (and loaded) only when they are visible on screen. So every time you scroll down or up a new row is created, loaded and the RowLoading event fired.
To disable the virtualization you can try to set this property:
VirtualizingStackPanel.VirtualizationMode="Standard"
Be aware that this can slow down the performance of your grid if you have a lot of rows.
Upvotes: 2