0

Basic listbox template

<ListBox Height="200"   
        x:Name="lstBox"    
        ScrollViewer.VerticalScrollBarVisibility="Visible"
       VirtualizingStackPanel.IsVirtualizing="True"      VirtualizingStackPanel.VirtualizationMode="Recycling"  VirtualizingStackPanel.CacheLength="2,3"
        VirtualizingStackPanel.CacheLengthUnit="Page"
         ItemTemplate="{StaticResource  DataTemplater}"
         ItemsSource="{Binding Source={StaticResource SearchedResults}}" 
        SelectedItem="{Binding CurrentItem}" 
        IsSynchronizedWithCurrentItem="True">
           <ListBox.Template>
                  <ControlTemplate TargetType="{x:Type ItemsControl}">
                       <ScrollViewer  >
                                <ItemsPresenter />
                       </ScrollViewer>
                    </ControlTemplate>
          </ListBox.Template>
           <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                      <VirtualizingStackPanel ScrollUnit="Pixel" Orientation="Vertical"  VirtualizationMode="Recycling" IsContainerVirtualizable="True" IsVirtualizing="True" IsItemsHost="True"/>
                 </ItemsPanelTemplate>
          </ListBox.ItemsPanel>
        </ListBox>

DataTemplater item template contains a stack panel with bound controls.Binding source is a data-table from data-set.

The problem here is virtualization not working, because I had a C# code lookup specified in the item template and that code is getting hit for all items in data table and not only for visible items?

How can I resolve this issue?

Rohith Nair
  • 1,080
  • 1
  • 17
  • 33

0 Answers0