Xceed DataGrid重置滚动条位置 [英] Xceed DataGrid Resets ScrollBar Position
问题描述
当我在Xceed DataGridControl中更改ItemsSource时,我的垂直和水平滚动条立即重置为顶部/左侧.
When I change the ItemsSource in the Xceed DataGridControl my vertical and horizontal scroll bars immediately get reset to the top/left.
有什么想法可以防止这种情况发生吗?
Any ideas how to prevent that from happening?
推荐答案
我终于修复并弄清楚了为什么每次刷新DataGrid时滚动条都跳到顶部/左侧.
I finally fixed and figured out why my scrollbars jump to the top/left each time my DataGrid refreshes.
显示绑定到视图而不是实际数据源(DataView)的XAML,因此每次刷新都会替换视图和数据源.绑定到DataView的结果是,滚动条不再跳转,并且网格现在像以前一样立即填充1-2秒.
Turns out the XAML binded to the View instead of to an actual datasource (DataView), thus each refresh replaced the view and the datasource. As a result of binding to a DataView, my scrollbars no longer jump, and my grid now populates instantly as before it tool 1-2 seconds.
我包括了代码更改,以防将来对其他人有所帮助.
I included my code changes in case that helps others in the future.
旧代码绑定到视图:
<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");
}
}
}
新代码绑定到DataView:
New code binds to a 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;
}
}
}
这篇关于Xceed DataGrid重置滚动条位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!