Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Recycling VirtualizationMode is not working as expected

$
0
0

We have a desktop application, in which we have a ListView which have KPage inside ListView.ItemTemplate

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

We noticed that the constructor of KPage (which is within the ItemTemplate) is always executed while viewing items inside the ListView, but what is 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 KPage created ..

Is it because we have customized ListView.ItemTemplate ? Please see the listview below
We also tried to set VirtualizingStackPanel.IsVirtualizing="True" and  VirtualizingStackPanel.VirtualizationMode="Recycling"for our customized KVirtualizingStackPanel but still, the Recycling is not working.

Any idea please?

===================================================

<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>




hopewise


Viewing all articles
Browse latest Browse all 18858

Trending Articles