Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ListView virtualization. How to disable ListView virtualization?

I have some troubles with custom ListView (CheckBoxes inside lost their states when scrolling ListView). Can I disable ListView virtualization without visual tree enumerating?

<ListView>
    <ListView.Resources>
        <Style TargetType="GridViewColumnHeader">
            <Setter Property="Visibility" Value="Collapsed" />
        </Style>
    </ListView.Resources>
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Address">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox Content="{Binding Address}"/>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="Name">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>
like image 577
Oomph Sonar Avatar asked Apr 29 '14 17:04

Oomph Sonar


1 Answers

As stated by H.B. in their answer here:

Set VirtualizingStackPanel.IsVirtualizing to false on the ListView or set a normal StackPanel as the ListView.ItemsPanel.

<ListView VirtualizingStackPanel.IsVirtualizing="False"/>

or

<ListView>
 <ListView.ItemsPanel>
     <ItemsPanelTemplate>
       <StackPanel></StackPanel>
      </ItemsPanelTemplate>
  </ListView.ItemsPanel>
 </ListView>
like image 127
123 456 789 0 Avatar answered Nov 11 '22 09:11

123 456 789 0