ItemsControl.ItemContainerGenerator 属性


获取与控件关联的 ItemContainerGeneratorGets the ItemContainerGenerator that is associated with the control.

 property System::Windows::Controls::ItemContainerGenerator ^ ItemContainerGenerator { System::Windows::Controls::ItemContainerGenerator ^ get(); };
public System.Windows.Controls.ItemContainerGenerator ItemContainerGenerator { get; }
member this.ItemContainerGenerator : System.Windows.Controls.ItemContainerGenerator
Public ReadOnly Property ItemContainerGenerator As ItemContainerGenerator



与控件关联的 ItemContainerGeneratorThe ItemContainerGenerator that is associated with the control. 默认值为 nullThe default is null.



ItemContainerGenerator负责为其主机生成用户界面 (UI) ,例如 ItemsControlAn ItemContainerGenerator is responsible for generating the user interface (UI) for its host, such as an ItemsControl. 它保留控件数据视图中项与相应对象之间的关联 UIElementIt maintains the association between the items in the data view of the control and the corresponding UIElement objects. 每个 ItemsControl 都有一个关联的项容器,其中包含项集合中的数据项。Every ItemsControl has an associated item container that contains a data item in the item collection. 您可以使用 ItemContainerGenerator 属性来访问与您的关联的项容器 ItemsControlYou can use the ItemContainerGenerator property to access the item container that is associated with your ItemsControl. 例如,如果您有一个数据绑定控件, TreeView 并且您希望 TreeViewItem 基于其索引或其关联数据项获取,则可以使用 ItemContainerGenerator.ContainerFromIndexItemContainerGenerator.ContainerFromItem 方法。For example, if you have a data-bound TreeView control and you want to get a TreeViewItem based on its index or its associated data item, you can use the ItemContainerGenerator.ContainerFromIndex or the ItemContainerGenerator.ContainerFromItem method. 或者,可以使用 ItemContainerGenerator.IndexFromContainerItemContainerGenerator.ItemFromContainer 方法来获取与给定生成的容器元素关联的索引或数据项。Alternatively, you can use the ItemContainerGenerator.IndexFromContainer or the ItemContainerGenerator.ItemFromContainer method to get the index or data item that is associated with a given generated container element.

IItemContainerGenerator接口还在高级方案中使用。The IItemContainerGenerator interface is also used in advanced scenarios. 通常,具有其自己的虚拟化面板实现的高级应用程序会调用接口的成员。Typically, advanced applications that have their own implementation of a virtualizing panel call members of the interface.