继承自itemsControl-如何更改项目的类型? [英] Inherited from an itemsControl - How to change the type of the items?
问题描述
我正在尝试改进 ListView
.这主要与 ListViewItem
类中的更改有关.所以我继承了两者,创建了两个服装控件:
I'm trying to improve ListView
. This mostly has to do with changed in the ListViewItem
class. So I inherited from both, creating two costume controls:
NestedListView : ListView
NestedListViewItem : ListViewItem
问题是,现在我希望 NestedListView
的< ItemsPresenter/>
呈现 NestedListViewItem
而不是常规的ListViewItems
.我该如何实现?
The problem is that now I want the NestedListView
's <ItemsPresenter/>
to present NestedListViewItem
s instead of regular ListViewItems
.
How do I achieve this?
(我几乎不知道如何 < ItemsPresenter/>
.因此,对该区域的任何解释都将有所帮助).
(I pretty much have no idea how <ItemsPresenter/>
works. So any explanation on that area could be helpful).
推荐答案
重写 GetContainerForItemOverride
方法并返回所需的项目容器类型:
Override the GetContainerForItemOverride
method and return the type of item container you want:
public class NestedListView : ListView
{
protected override DependencyObject GetContainerForItemOverride()
{
return new NestedListViewItem();
}
protected override bool IsItemItsOwnContainerOverride(object item)
{
return item is NestedListViewItem;
}
}
这篇关于继承自itemsControl-如何更改项目的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!