16

我在我的 Model (Class X) Boolean property:IsSelected中有,链接到WPF DataGrid如下:

<DataGrid  SelectedIndex="{Binding SelectedXIndex,Mode=TwoWay}" 
           DataContext="{Binding MyViewModel}" 
           ItemsSource="{Binding ListX}" AutoGenerateColumns="False">
     <DataGrid.RowStyle>
         <Style TargetType="{x:Type DataGridRow}">
             <Setter Property="IsSelected" 
                     Value="{Binding IsSelected, Mode=TwoWay, 
                             UpdateSourceTrigger=PropertyChanged}"/>
         </Style>
     </DataGrid.RowStyle>
</DataGrid>

ListX- ObservableCollection

IsSelecte- 调用 NotifyPropertyChange

它工作得很好。

但是当我有很多行时,我需要滚动查看它们,然后按下运行以下功能的“全选”按钮,他只选择了一些行而不是全部:(即使所有IsSelected 上的列表为true )

public void SelectAll()
{
    ListX.All(c => c.IsSelected = true);
}

我不明白为什么会这样?

4

1 回答 1

13

这就是最终帮助我的原因:

我放入了DataGrid:

VirtualizingStackPanel.VirtualizationMode="Standard"
于 2013-02-19T06:11:20.790 回答