Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IsSelected Binding in WPF DataGrid

I have in my Model (Class X) Boolean property: IsSelected, is linked to a WPF DataGrid as follows:

<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- Call to NotifyPropertyChange

It works great.

But when I have a lot of rows, that I need to scroll to see them, and I press the button "Select All" that runs the following function, he chooses me only some of the rows and not all: (Even though all the IsSelected on the list is true)

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

I can not understand why this is happening?

like image 799
Hodaya Shalom Avatar asked Feb 17 '13 06:02

Hodaya Shalom


1 Answers

that's what helped me finally:

I put in the DataGrid:

VirtualizingStackPanel.VirtualizationMode="Standard"
like image 124
Hodaya Shalom Avatar answered Nov 08 '22 08:11

Hodaya Shalom