views:

424

answers:

1

Hi !

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 Template 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.

A: 

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
}
Jalfp