Click here to Skip to main content
15,851,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We have a desktop application, in which we have a ListView, the `ListView.ItemTemplate` is a KPageScrollViewer which extends `ScrollViewer`

Although we set `VirtualizingStackPanel.IsVirtualizing="True"` and `VirtualizingStackPanel.VirtualizationMode="Recycling"`

We noticed that the constructor of KPageScrollViewer (which is within the `ItemTemplate`) is always executed while viewing items inside the ListView.

What we expected is that it will be created 4 to 5 times, then, the same instances will be used to view data because we are using Recycling mode, but that won't happen, thus we will end up with more and more KPageScrollViewer instances created ..

Is it because we have customized `ListView.ItemsPanel` ?

HTML
<ListView.ItemsPanel>
            <ItemsPanelTemplate >
                <p:KVirtualizingStackPanel IsItemsHost="True"

Any idea please?
I wonder which reasons could lead to losing recycling feature?



HTML
<ListView  x:Class="KETAB.KStudio.Stage.PagesView"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:p="clr-namespace:KETAB.KStudio.Stage"
           Name="PagesList" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden"
           Loaded="instScroll_Loaded"
           AllowDrop="True"
MouseMove="PagesList_MouseMove"
          ScrollViewer.PanningMode="None"
            VirtualizingStackPanel.IsVirtualizing="True"
                    VirtualizingStackPanel.CleanUpVirtualizedItem="PagesList_CleanUpVirtualizedItem"
                    VirtualizingStackPanel.VirtualizationMode="Recycling"
    >



    <ListView.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary  Source="Resources/StageResources.xaml"/>
                <ResourceDictionary Source="/KETAB.KStudio.UserControls;component/ScrollViewerStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <SolidColorBrush  x:Key="{x:Static SystemColors.HighlightBrushKey}" Opacity="0.4" Color="Transparent" />
            <SolidColorBrush  x:Key="{x:Static SystemColors.ControlBrushKey}"  Opacity="0.4" Color="Transparent"  />
            <!--<p:PageWidthConverter x:Key="PageWidthConverter" />-->
            <p:PageWidthConverter x:Key="pageWidthConverter" />
            <p:PageHeightConverter x:Key="pageHeightConverter" />
            <Style  TargetType="{x:Type ListViewItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListViewItem}">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="FocusVisualStyle"
            Value="{x:Null}"/>
            </Style>
        </ResourceDictionary>
    </ListView.Resources>
    <ListView.ItemTemplate>
        <DataTemplate x:Name="PagesViewDataTemplate">
            <DataTemplate.Resources>
                <Style x:Key="PageHostStyle" TargetType="{x:Type p:KPage}">
                </Style>
            </DataTemplate.Resources>
            <p:KPageScrollViewer Name="ScrollContainer" Padding="{Binding ElementName=PagesList, Path=PageScrollViewerPadding}"
                       >
                <Grid x:Name="MarginStack" >
                    <p:KPage x:Name="KPage" SizeChanged="KPage_SizeChanged" >

                    </p:KPage>
                </Grid>
            </p:KPageScrollViewer>
        </DataTemplate>
    </ListView.ItemTemplate>

    <ListView.ItemsPanel>
        <ItemsPanelTemplate >
            <p:KVirtualizingStackPanel IsItemsHost="True"  x:Name="WrapPanel1" Orientation="{Binding ElementName=PagesList, Path=MyOrientation}" VerticalAlignment="Center" HorizontalAlignment="Center"
            >

            </p:KVirtualizingStackPanel>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>

</ListView>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900