2010-05-07 144 views

回答

3

我終於修好了,並找出爲什麼每次我的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; 
     } 
    } 
}