ItemsControl

Introduction

ItemsControl provides a way to display a collection of controls. By default all contained controls are stacked and allow scrolling with a ScrollBar.

circle-info

ItemsControl is similar to ListBox, but it is more general since it does not support selection. When items are added to the Items property the ItemsControl does not create a control which inherits from ListBoxItem. Similarly, its VisualTemplate does not need to be a type which supports a ListBoxItem.

ItemsControl inherits from ScrollViewer. For more information about inherited proerties, see the ScrollViewer page.

Code Example: Adding to Items Property

If an object is added to the Items property then the ItemsControl creates a view to represent this. By default this is a Label instance, but it can be customized through the VisualTemplate property.

The following code creates ten Labels by adding integers to the Items property.

// Initialize
var itemsControl = new ItemsControl();
itemsControl.AddToRoot();
for(int i = 0; i < 10; i++)
{
    itemsControl.Items.Add(i);
}

Try on XnaFiddle.NETarrow-up-right

ItemsControl with ten items

Code Example: Fixed-Size Scrollable List

Setting explicit Width and Height values gives the ItemsControl a fixed size so that its content scrolls when it overflows. This is useful for displaying a non-selectable scrollable list in a fixed area.

Try on XnaFiddle.NETarrow-up-right

Last updated

Was this helpful?