Gets or sets the Style that is applied to the container element generated for each item.
Assembly: PresentationFramework (in PresentationFramework.dll)
You use this property or the ItemContainerStyleSelector property to set a style to affect the appearance of the elements that contain the data items. For example, for ListBox, the generated containers are ListBoxItem controls; for ComboBox, they are ComboBoxItem controls.
The ItemsControl provides great flexibility for visual customization and provides many styling and templating properties. To affect the layout of the items, use the ItemsPanel property. If you are using grouping on your control, you can use the GroupStyle or GroupStyleSelector property. To specify the visualization of data objects, use the ItemTemplate or ItemTemplateSelector property. For more information about when to specify an ItemTemplate, see Data Templating Overview.
One of the following: StaticResource, or DynamicResource. Unless the styles themselves contain references to potential run-time references such as system resources or user preferences, StaticResource reference to a style is usually recommended for performance.
x:Key string value referring to the style being requested as a resource.
The following example demonstrates how to use this property. Consider the following data-bound ListBox:
To create a style for the elements that contain the data items, create a ListBoxItem style, as shown in the following example. The style is applied to all ListBoxItem elements within the scope the style is defined in.
The ListBoxItem is the container element for the ListBox control. Therefore, an alternative to the preceding is to set the property of the ListBox to the defined style. To do that, give the ListBoxItem style an x:Key so it is available as a resource:
Next, set theproperty to the resource, as in the following example:
Both of the preceding scenarios produce the same result. However, one of the advantages of making the style available as a resource is that you can reuse the style. Setting theproperty explicitly can also provide greater readability.
For the complete example, see Introduction to Styling and Templating Sample.
The following example is designed to illustrate the function of the different styling and templating related properties provided by the ItemsControl. The ItemsControl in this example is bound to a collection of Task objects. For demonstration purposes, the styles and templates in this example are all declared inline.
The following is a screenshot of the example when it is rendered:
Available since 3.0