ItemsControl.ItemContainerStyleSelector 属性


获取或设置可应用于每个所生成容器元素的样式的自定义样式选择逻辑。Gets or sets custom style-selection logic for a style that can be applied to each generated container element.

 property System::Windows::Controls::StyleSelector ^ ItemContainerStyleSelector { System::Windows::Controls::StyleSelector ^ get(); void set(System::Windows::Controls::StyleSelector ^ value); };
public System.Windows.Controls.StyleSelector ItemContainerStyleSelector { get; set; }
member this.ItemContainerStyleSelector : System.Windows.Controls.StyleSelector with get, set
Public Property ItemContainerStyleSelector As StyleSelector


一个 StyleSelector 对象,其中包含选择要用作 ItemContainerStyle 的样式的逻辑。A StyleSelector object that contains logic that chooses the style to use as the ItemContainerStyle. 默认值为 nullThe default is null.



使用 ItemContainerStyle 属性可以设置样式,以影响包含数据项的元素的外观。You use the ItemContainerStyle property to set a style to affect the appearance of the elements that contain the data items. 例如,对于 ListBox,生成的容器是 ListBoxItem 控件;对于 ComboBox,它们是 ComboBoxItem 控件。For example, for ListBox, the generated containers are ListBoxItem controls; for ComboBox, they are ComboBoxItem controls. 如果定义了多个样式,并且需要提供逻辑来选择要应用的样式,则使用 ItemContainerStyleSelector 属性,而不是 ItemContainerStyle 属性。If you have more than one style defined and need to supply logic to choose which one to apply, then you use the ItemContainerStyleSelector property instead of the ItemContainerStyle property. 请注意,如果设置 ItemContainerStyle 属性,则忽略此属性。Note that this property is ignored if the ItemContainerStyle property is set.

ItemsControl 为视觉对象自定义提供了极大的灵活性,并提供了许多样式设置和模板化属性。The ItemsControl provides great flexibility for visual customization and provides many styling and templating properties. 若要影响项的布局,请使用 ItemsPanel 属性。To affect the layout of the items, use the ItemsPanel property. 如果对控件使用分组,则可以使用 "GroupStyle" 或 "GroupStyleSelector" 属性。If you are using grouping on your control, you can use the GroupStyle or GroupStyleSelector property. 若要指定数据对象的可视化,请使用 ItemTemplateItemTemplateSelector 属性。To specify the visualization of data objects, use the ItemTemplate or ItemTemplateSelector property. 有关何时指定 ItemTemplate的详细信息,请参阅数据模板化概述For more information about when to specify an ItemTemplate, see Data Templating Overview.

依赖项属性信息Dependency Property Information

标识符字段Identifier field ItemContainerStyleSelectorProperty
元数据属性设置为 trueMetadata properties set to true None