views:

119

answers:

2

Hi,

This might be a crazy question.

Suppose a collection that has a a few entries, some of them are just empty string. Is it possible to write the ItemsControl to use different DateTempalte if the content is empty string?

Thanks a million times

+1  A: 

Maybe this will help

Different DataTemplates for different data

http://www.thejoyofcode.com/Different%5FDataTemplates%5Ffor%5Fdifferent%5Fdata.aspx

it was really helpful for me.

Holli
excellent, thanks for the link
+4  A: 

Yeah. There are many ways to do this. Most common: (DataTemplate + DataTrigger) or ItemTemplateSelector.

In DataTemplate+DataTrigger scenario in the DataTrigger you will update content of your DataTemplate via setters. With ItemTemplateSelector you can decide based on your item which DataTemplate to use.

I really encourage you to read wonderful series of articles by dr. Wpf "ItemsControl: A to Z". If you spend 4 - 6 hours on reading today you will save much more hours later, when you find yourself one on one with problems in ItemsControl (hopefully not right before the deadline).

More details on your particular question is here: 'D' is for DataTemplate

Anvaka
cool, very helpful series, thanks!