Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Windows Phone 7 ItemsControl Virtualization using VirtualizingStackPanel in Silverlight

DZone's Guide to

Windows Phone 7 ItemsControl Virtualization using VirtualizingStackPanel in Silverlight

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

Usually I am using ListBox control in my Windows Phone 7 Silverlight applications to display a scrollable list of child controls. ListBox offers UI virtualization, that means that UI is loading ListBox items on demand to increase the performance and reduce memory allocation. One of the main keys to that is in using VirtualizingStackPanel as ItemsPanel Template for ListBox control.

Lately in one of my Windows Phone 7 projects I had to replace ListBox with ItemsControl, but ItemsControl does not offer UI virtualization for child items by default, so I had to add the same VirtualizingStackPanel to ItemsPanelTemplate element. Also I have modified the Template element to be able to add and access ScrollViewer for ItemsControl.

<ItemsControl>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.Template>
        <ControlTemplate TargetType="ItemsControl">
                <ScrollViewer>
                    <ItemsPresenter/>
                </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <!-- place your controls here-->
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

 

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}