2012-09-15 4 views
5

ItemsControl 개체에서 ItemContainer 유형을 결정하고 싶습니다.WPF ItemsControl에 대한 일반 ItemContainer 형식을 얻는 방법

var item = control as ItemsControl; 
    //HOW to get child container Type? 

예 혼합이 어떻게하는지 :

enter image description here

혼합 든 현재 TabControl 유형의 하위 항목이 TabItem 것을 결정한다.

코드에서 동일한 작업을 수행하는 방법은 무엇입니까?

답변

8

ItemsControl에서 파생 된 대부분의 클래스에 StyleTypedPropertyAttribute이 있습니다. Property"ItemContainerStyle"과 같습니다. 이 속성의 StyleTargetType 속성은 항목 유형을 제공해야합니다.

기본 클래스의 특성을 가져 가지 않도록주의해야합니다. 또한 대부분의 유형 (TabControl, ListBox)에서 작동하지만 DataGrid과 같은 일부 클래스에는이 속성이 주석으로 표시되지 않습니다.

var _itemsContainerTypeByContainerType = new Dictionary<Type, Type> { 
    { typeof(ComboBox), typeof(ComboBoxItem) }, 
    { typeof(ContextMenu), typeof(MenuItem) }, 
    { typeof(DataGrid), typeof(DataGridRow) }, 
    { typeof(DataGridCellsPresenter), typeof(DataGridCell) }, 
    { typeof(DataGridColumnHeadersPresenter), typeof(DataGridColumnHeader) }, 
    { typeof(HeaderedItemsControl), typeof(ContentPresenter) }, 
    { typeof(ItemsControl), typeof(ContentPresenter) }, 
    { typeof(ListBox), typeof(ListBoxItem) }, 
    { typeof(ListView), typeof(ListViewItem) }, 
    { typeof(Menu), typeof(MenuItem) }, 
    { typeof(MenuBase), typeof(MenuItem) }, 
    { typeof(MenuItem), typeof(MenuItem) }, 
    { typeof(MultiSelector), typeof(ContentPresenter) }, 
    { typeof(Selector), typeof(ContentPresenter) }, 
    { typeof(StatusBar), typeof(StatusBarItem) }, 
    { typeof(TabControl), typeof(TabItem) }, 
    { typeof(TreeView), typeof(TreeViewItem) }, 
    { typeof(TreeViewItem), typeof(TreeViewItem) } 
}; 
: 여기

내가 내장 된 프레임 워크 타입에 사용하는 목록입니다
관련 문제