Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否在WPF自定义控件中使用ListBox而不是ItemsPresenter?_Wpf_Custom Controls_Generics_Controltemplate - Fatal编程技术网

是否在WPF自定义控件中使用ListBox而不是ItemsPresenter?

是否在WPF自定义控件中使用ListBox而不是ItemsPresenter?,wpf,custom-controls,generics,controltemplate,Wpf,Custom Controls,Generics,Controltemplate,我正在为我的WPF自定义控件编写一个通用控件模板。 但是使用ItemsPresenter我只得到了原始数据列表。。 与ListBox相比,ListBox具有我需要的所有功能 使用列表框而不是ItemsPresenter是否错误 我想要的是 如果我编写了一个使用列表框的通用模板,并在代码隐藏中注册了一些列表框特定事件,并且有人用自己的控件模板覆盖了我的通用模板,其中包含一个不包含该事件的项控件,它将引发异常。对于ItemsPresenter,每个人都可以随心所欲地使用 谢谢。我想您可以添加一些测试

我正在为我的WPF自定义控件编写一个通用控件模板。 但是使用
ItemsPresenter
我只得到了原始数据列表。。 与ListBox相比,ListBox具有我需要的所有功能

使用
列表框
而不是
ItemsPresenter
是否错误

我想要的是 如果我编写了一个使用
列表框
的通用模板,并在代码隐藏中注册了一些
列表框
特定事件,并且有人用自己的
控件模板
覆盖了我的通用
模板
,其中包含一个不包含该事件的
项控件
,它将引发异常。对于
ItemsPresenter
,每个人都可以随心所欲地使用


谢谢。

我想您可以添加一些测试,看看模板中的ItemsControl是否是列表框。例如:

var itemsControl = this.Template.FindName("PART_Items", this);
if(itemsControl is ListBox)
{
  // wire additional event handler here
}