views:

155

answers:

1

Given the object graph below I need to have 2 different style applied depending on whether the Parent object has any children or not.

I am unsure how to go about setting the style on a condition like this, can anyone help please?

Parent (Object)
 Prop1 (string)
 Prop2 (string)
    Children (List<Object>)

Thanks in advance.

+1  A: 

You can try using a IValueConverter and bind that to the Style property, passing the current object as a conversion parameter. Within your IValueConverter, return the correct style.

Alternatively, you could use a DataTemplateSelector and swap DataTemplates based on Children.Count. I don't know enough about your objects/properties to know whether you're in need of a different DataTemplate or a different style for the same DataTemplate.

micahtan
Selectors probably aren't a good bet because the selector won't re-run if a child is added or removed. Also it's not clear whether he's in WPF or Silverlight, but if it's Silverlight, I think that doesn't have selectors.
itowlson