【问题标题】:Xceed DataGrid Resets ScrollBar PositionXceed DataGrid 重置滚动条位置
【发布时间】:2010-05-07 22:57:51
【问题描述】:

当我更改 Xceed DataGridControl 中的 ItemsSource 时,我的垂直和水平滚动条会立即重置到顶部/左侧。

有什么办法可以防止这种情况发生吗?

【问题讨论】:

    标签: wpf xceed-datagrid xceed


    【解决方案1】:

    我终于修复并弄清楚了为什么每次 DataGrid 刷新时我的滚动条都会跳到顶部/左侧。

    原来 XAML 绑定到视图而不是实际数据源 (DataView),因此每次刷新都会替换视图和数据源。由于绑定到 DataView,我的滚动条不再跳跃,并且我的网格现在像之前一样在 1-2 秒内立即填充。

    我包含了我的代码更改,以防将来帮助其他人。

    旧代码绑定到视图:

     <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:

    <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;
          }
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-05
      • 1970-01-01
      • 2012-01-21
      • 2011-04-03
      • 2015-01-26
      • 2017-02-03
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      相关资源
      最近更新 更多