0

I have a virtualizing stack panel in my ItemsControl, in a scroll viewer. It doesn't seem to be virtualizing:

<Page
x:Class="IWalker.Views.FullTalkAsStripView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:IWalker.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <ScrollViewer x:Name="theScrollViewer" VerticalScrollMode="Disabled" HorizontalScrollMode="Auto" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">
        <ItemsControl x:Name="SlideStrip">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <local:PDFPageUserControl Margin="0 0 5 0" Height="{Binding Path=ActualHeight, ElementName=SlideStrip, Mode=OneWay}" ViewModel="{Binding}" RespectRenderingDimension="Vertical" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </ScrollViewer>
</Grid>
</Page>

The PDFPageUserControl prints out a little debug message when it is instantiated - and I always get one even when I get more than 50 items. The SlideStrip.ItemsSource is databound, so I don't think that is the problem (via ReactiveUI):

this.OneWayBind(ViewModel, x => x.Pages, y => y.SlideStrip.ItemsSource);

Where Pages is a ReactiveUI list.

What have I missed? Do I need to set IsVirtualizing to true? Where is that attached property in this case (since this isn't a ListBox)?

BTW, I will never have a large number of controls. The issue is that each control holds onto an image, and a large one at that (e.g. full screen on a high DPI display). All I really want to do is release the image when each PDF control is not visible, and re-load when it is. So there may be a better way to solve my problem.

Gordon
  • 3,012
  • 2
  • 26
  • 35
  • I don't have a specific answer to your virtualization question, however I posted an answer to SO ([Loading a large amount of images to be displayed in a WrapPanel](http://stackoverflow.com/a/27865101/4265041)) that may help you. If you scroll down to "Only loading thumbnails when in view" you'll find a custom `ScrollViewer` with an attached Boolean property that is set when an item scrolls into view. This property can be used in a trigger to show or hide something. This approach may work for you if you use a `ListBox` as your container and only show the PDF control when it is "visible". – Steven Rands Jan 29 '15 at 16:12
  • I just noticed that you tagged this as a Windows Store question, not WPF, so my solution may not work for you. Might be worth a try though. – Steven Rands Jan 29 '15 at 16:14
  • Ah, brilliant. This was exactly what I was thinking I might try when I mentioned another approach - I just am new enough not to have known. I suspect the WPF vs WS differences will not matter in this case. I am going to attempt this approach, and if it is not doable, or needs some differences from your suggestion, I'll report back! – Gordon Jan 29 '15 at 22:45
  • Oi! I thought it would be the same. In principle, I think the windows store solution is similar. And while I was able to get attached properties to work in isolated cases, I wasn't able to get it properly working inside a list like this. I need to extract a test project to debug. But in the meantime, the geometry calculations based on your solution can be found here: https://github.com/gordonwatts/IndicoWalker/blob/master/IWalker/IWalker.Windows/Util/OnScreenTrackingHelper.cs Thanks so much again! – Gordon Feb 01 '15 at 03:48

0 Answers0