Why doesn't recycling work?

We have a desktop application in which we have ListView, ListView.ItemTemplate is a KPageScrollViewer that extends ScrollViewer

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

We noticed that the KPageScrollViewer constructor (which is inside the ItemTemplate ) always executes while viewing items inside the ListView.

We expected it to be created 4-5 times, then the same instances will be used to view the data, because we use the recirculation mode, but this will not happen, so we will get more and more instances of KPageScrollViewer created.

Is it because we customized ListView.ItemsPanel ?

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

Any idea please? I wonder what causes the loss of the recycling function?

 <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}" Height="{Binding ElementName=PagesList, Path=ScaleY, Converter={StaticResource pageHeightConverter}}" Width="{Binding ElementName=PagesList, Path=ScaleX, Converter={StaticResource pageWidthConverter}}" MaxHeight="{Binding ElementName=PagesList, Path=Height}" MaxWidth="{Binding ElementName=PagesList, Path=Width}" ScrollViewer.HorizontalScrollBarVisibility="{Binding ElementName=PagesList, Path=PageScrollVisibilityHori}" ScrollViewer.VerticalScrollBarVisibility="{Binding ElementName=PagesList, Path=PageScrollVisibilityVert}" > <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" ClipToBounds="{Binding ElementName=PagesList, Path=PanelClipToBounds}" Height="{Binding ElementName=PagesList, Path=ScaleY, Converter={StaticResource pageHeightConverter}}" Width="{Binding ElementName=PagesList, Path=ScaleX, Converter={StaticResource pageWidthConverter}}" MaxHeight="{Binding ElementName=PagesList, Path=Height}" MaxWidth="{Binding ElementName=PagesList, Path=Width}" > </p:KVirtualizingStackPanel> </ItemsPanelTemplate> </ListView.ItemsPanel> </ListView> 

EDIT

ListView is used here: (p: PagesView)

 <Window x:Class="KETAB.KStudio.UI.WindowMain" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:kStudioControls="clr-namespace:KETAB.KStudio.UI" xmlns:toolBoxUIPanel="clr-namespace:KETAB.KStudio.UI" xmlns:Controls="clr-namespace:KETAB.KStudio.UserControls;assembly=KETAB.KStudio.UserControls" xmlns:p="clr-namespace:KETAB.KStudio.Stage;assembly=KETAB.KStudio.Stage" xmlns:tb="http://www.hardcodet.net/taskbar" SizeChanged="Window_SizeChanged" WindowState="Maximized" WindowStyle="None" Background="Transparent" ResizeMode="CanResizeWithGrip" PreviewKeyUp="WindowMain_PreviewKeyUp" Closed="WindowMain_Closed" Stylus.IsPressAndHoldEnabled="False" Stylus.IsTapFeedbackEnabled="False" Stylus.IsTouchFeedbackEnabled="False" Stylus.IsFlicksEnabled="False" AllowsTransparency="True"> <Grid FlowDirection="LeftToRight" Name="MainUIContainer"> <Grid.RowDefinitions> <RowDefinition Height="auto" MinHeight="0" /> <RowDefinition /> </Grid.RowDefinitions> <tb:TaskbarIcon x:Name="MyNotifyIcon" IconSource="/KETABStudio;component/KStudioControls/KStudioIcons/Notify.ico" ToolTipText="KETAB Studio" Visibility="Collapsed"/> <Border Name="borderContainer" ClipToBounds="True" Margin="0,0,0,0" Grid.Row="1" Grid.Column="0" BorderThickness="2, 0, 2, 2" BorderBrush="{StaticResource MainWindowBorderColor}" Background="White"> <Grid Background="Transparent" ClipToBounds="True" Name="MainUISplit" SizeChanged="MainUISplit_SizeChanged"> <!--main backgound depends on this grid--> <Grid.RowDefinitions> <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="auto" /> </Grid.ColumnDefinitions> <Grid Background="{StaticResource background}" Margin="0" ClipToBounds="True" Name="applicationBackground"> <Rectangle Name="OpacityRectangle" Visibility="Hidden" Margin="0,0,-60,0" Fill="Black" ></Rectangle> </Grid> <!--Page Area--> <Grid Grid.Column="0" Grid.Row="0" Margin="0" Name="PageArea" AllowDrop="True"> <p:PagesView Name="PageList" /> <Controls:PageLoadingControl x:Name="pageLoadingControl" Visibility="Collapsed"/> <Controls:HelpMode x:Name="HelpModeInstance" Visibility="Collapsed"/> </Grid> </Grid> </Border> </Grid> </Window> 
+6
source share
1 answer

I read the following, which may be useful ... related to how you use the ItemPanel: Virtualization of an ItemsControl? - I understand this is not quite the same topic, but it has a good explanation on a very similar problem.

Hope this helps.

0
source

All Articles