在WPF DataGrid中选择绑定

Hod*_*lom 16 wpf binding datagrid mvvm

我在我的Model(Class X)布尔属性中: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>
Run Code Online (Sandbox Code Playgroud)

ListX- ObservableCollection

IsSelecte- 调用NotifyPropertyChange

它很棒.

但是当我有很多行时,我需要滚动查看它们,然后按下运行以下功能的"全选"按钮,他只选择了一些行而不是全部:(尽管所有名单上的IsSelected是真的)

public void SelectAll()
{
    ListX.All(c => c.IsSelected = true);
}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么会这样?

Hod*_*lom 13

那最终帮助了我的是:

我放入了DataGrid:

VirtualizingStackPanel.VirtualizationMode="Standard"
Run Code Online (Sandbox Code Playgroud)