开发者

ListBox instead of ItemsPresenter in WPF Custom Control?

开发者 https://www.devze.com 2022-12-18 15:27 出处:网络
I\'m writing a generic control template for my WPF Custom Control. But with ItemsPresenter I only got raw list of Data..

I'm writing a generic control template for my WPF Custom Control. But with ItemsPresenter I only got raw list of Data.. Compared to the ListBox, the ListBox has all features I need.

Is it wrong to use a ListBox instead of ItemsPresenter ?

What I'm after is that if I write a generic Temp开发者_StackOverflow中文版late that uses a ListBox and in code behind I register some ListBox specific events and somebody overrides my generic Template with his own ControlTemplate witn an ItemsControl inside that does not possess that event, it will raise an Exception. In case of ItemsPresenter, everyone could use what he wants to.

Thanks.


I think you could add some test to see if the ItemsControl in the template is a ListBox or not. For example:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号