我正在为我的WPF自定义控件编写一个通用控件模板。但是对于ItemsPresenter,我只得到了原始的数据列表。与ListBox相比,ListBox拥有我需要的所有功能。
使用ListBox而不是ItemsPresenter是错误的吗?
我想要的是,如果我编写了一个使用ListBox的通用模板,并且在后面的代码中注册了一些ListBox特定的事件,并且有人用他自己的ControlTemplate覆盖了我的泛型Template --在不拥有该事件的ItemsControl中,则会引发异常。在ItemsPresenter的情况下,每个人都可以使用他想要的。
谢谢。
发布于 2010-01-26 15:51:11
我认为您可以添加一些测试来查看模板中的ItemsControl是否为ListBox。例如:
var itemsControl = this.Template.FindName("PART_Items", this);
if(itemsControl is ListBox)
{
// wire additional event handler here
}https://stackoverflow.com/questions/2139772
复制相似问题