ItemContainer
既存のItemsControl
オブジェクトから型を判別したい。
var item = control as ItemsControl;
//HOW to get child container Type?
Blend でそれがどのように行われるかの例:
Blend はどういうわけか、現在のTabControl
タイプの子項目がであると判断しますTabItem
。
コードで同じことを行う方法は?
ItemContainer
既存のItemsControl
オブジェクトから型を判別したい。
var item = control as ItemsControl;
//HOW to get child container Type?
Blend でそれがどのように行われるかの例:
Blend はどういうわけか、現在のTabControl
タイプの子項目がであると判断しますTabItem
。
コードで同じことを行う方法は?
StyleTypedPropertyAttribute
から派生したほとんどのクラスにがありItemsControl
ます。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) }
};