Items in the Control

ItemsControl stores its content in an Items property (of type ItemCollection). Each item can be an arbitrary object (System.Object) that by default gets rendered just as it would inside a content control. In other words, any UIElement is rendered as expected, and (ignoring data templates) any other type is rendered as a TextBlock containing the string returned by its ToString method.

The simple ListBox control shown in Chapter 2, “Mastering XAML,” is an items control. Whereas Chapter 2 always adds ListBoxItems to the Items collection, the following example adds arbitrary objects to Items instead (all done in XAML for convenience):

<ListBox xmlns:sys="using:System">   <Button>Button</Button

Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.