0

For my project i need a scatterview but let's call it a listbox for people who don't work with the surface sdk :) , and it's bound to an observablecollection of objects in my viewmodel. Depending the kind of object, i use a different datatemplate (images, video's,...)

The container for these items is by default a listboxitem.

But there is a special object where i need more than a normal listboxitem as container, so i created my customlistboxcontainer. Here if found how to use that container:

Have a databound WPF Listbox generate subclassed ListboxItems

but this is not enough. I need to check at runtime what item is added to the collection, and choose the correct container for it (listboxitem, customlistboxitem). I can't seem to get is work.

Has anybody some experienxe with this?

Thx,

Bjorn

Community
  • 1
  • 1
  • Well, you could be a little more specific about what items are you trying to add, maybe it will turn out that you don't need a special container after all. And if you really do, you could elaborate on how you implemented adding items functionality. – Community Driven Business May 10 '12 at 13:34

1 Answers1

0

If you need to provide a different template for different types of items I suggest providing a DataTemplateSelector for your ListBox. I think the MSDN example is pretty clear on how to implement it, but let us know if you need further help.

Update: Here's an another tutorial to get you started.

Dan Busha
  • 3,723
  • 28
  • 36
  • Thanks for the help, but that is not enough. I'm using that allready to have different views, but i really need different container because some methods need to be overriden. And with a datatemplateselector you can't choose the container. – Bjorn Vdkerckhove May 10 '12 at 14:20
  • @BjornVdkerckhove How about filling your ObservableCollection with the MyListBoxItem and overriding the IsItemItsOwnContainerOverride on your ListBox to always return true? It's not pure MVVM, but it will allow you specify the container prior to binding. – Dan Busha May 10 '12 at 16:28