Xceed DataGrid Resets the position of the ScrollBar
1 answer
I finally got it right and figured out why my scrollbars are jumping to the top / left side every time the DataGrid is updated.
Turns off XAML that is bound to the view and not the actual data source (DataView), so each update replaces the view and data source. As a result of binding to the DataView, my scrollbars no longer jump and my grid now fills up instantly as the tool is 1-2 seconds before.
I've included my code changes in case it helps others in the future.
The old code is linked for viewing:
<xcdg:DataGridControl Name="FileGrid"
AutoCreateColumns="False"
SelectionMode="Extended"
ReadOnly="True"
ItemsSource="{Binding FileGridDataSource}"
ItemScrollingBehavior="Immediate"
NavigationBehavior="RowOnly">
</xcdg:DataGridControl>
public sealed class DataGridViewModel : ViewModelBase
{
public DataGridCollectionView FileGridDataSource
{
get
{
return _fileGridDataBoundSource;
}
set
{
_fileGridDataBoundSource = value;
NotifyPropertyChanged("FileGridDataSource");
}
}
}
The new code binds to the DataView:
<Window.Resources>
<xcdg:DataGridCollectionViewSource x:Name="FileGridView"
x:Key="fileView"
Source="{Binding Path=GridData}"
AutoFilterMode="And"
AutoCreateItemProperties="True"
AutoCreateForeignKeyDescriptions="True"
DefaultCalculateDistinctValues="False"/>
</Window.Resources>
<Grid>
<xcdg:DataGridControl Name="FileGrid"
AutoCreateColumns="False"
SelectionMode="Extended"
ReadOnly="True"
ItemsSource="{Binding Source={StaticResource fileView}}"
ItemScrollingBehavior="Immediate"
NavigationBehavior="RowOnly">
</xcdg:DataGridControl>
</Grid>
public sealed class DataGridViewModel : ViewModelBase
{
private DataTable _dt = new DataTable("MyDataTable");
public DataView GridData
{
get
{
return _dt.DefaultView;
}
}
}
+3
a source to share