#995 – ListBox Uses UI Virtualization by Default

List-based controls in WPF are comprised of a panel that contains a child UIElement for each item in the list.  The visual tree for a ListBox includes a VirtualizingStackPanel as a container for a series of ListBoxItem instances.  The ListBoxItem is the user interface element that renders an item from the list.

994-002

When a list contains a large number of items, it would take a long time and a large amount of memory to create a ListBoxItem for each element in the list.

To improve performance, a ListBox uses UI virtualization by default.  UIElement-based objects are created only for the items currently being displayed in the list.  New UIElements are then created as additional items are scrolled into view.

We can see this by binding a ListBox to a collection containing 1,000 elements and then looking at its visual tree.  ListBoxItems have been created for only the first few items.

995-001

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #995 – ListBox Uses UI Virtualization by Default

  1. Pingback: Dew Drop – January 27, 2014 (#1710) | Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: