ItemTemplates in Collections

Mar 14, 2011 at 11:31 AM

Hi,

I'm binding to a List<> property , with each item derived from  IPropertyElement interface.

Eg.

List<IPropertyElement> Items

How can I apply a template based on the derived IPropertyElement type (ie. like an ItemTemplateSelector)?

Thanks.

Coordinator
Mar 19, 2011 at 9:17 AM

I am not sure if I understand what you need here. You can implement a custom editor for the List<IPropertyElement> type. The data template for the custom editor could be an ItemsControl with an ItemTemplateSelector.

If you want each element in the List to be a "property", I think you must implement a custom type descriptor provider. See the CustomTypeDescriptorDemo that does this for a Dictionary. 

Mar 20, 2011 at 5:33 PM
objo wrote:

The data template for the custom editor could be an ItemsControl with an ItemTemplateSelector.

 I had spent time looking at the CustomTypeDescriptorDemo, but I didn't realise that a second level of template selection was needed (there's essentially a customer editor for the List<T> item, but also the ItemControl/TemplateSelector)

 This is exactly the information I needed! Thanks.