XAML:
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel >
<Grid Width="335" >
<TextBlock Text="{Binding Body}" />
</Grid>
</StackPanel>
</DataTemplate>
<DataTemplate >
<StackPanel >
<Grid Width="335" >
<Image Source="{Binding Image}" />
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
CS:
public class GardenConverter : ContentControl
{
public DataTemplate TextTemplate { get; set; }
public DataTemplate ImageTemplate { get; set; }
protected override void OnContentChanged(object oldContent, object newContent)
{
base.OnContentChanged(oldContent, newContent);
// apply the required template
GardenObject garden = newContent as GardenObject;
if (garden.image == "0")
{
ContentTemplate = TextTemplate;
}
else
{
ContentTemplate = ImageTemplate;
}
}
}