WPF/Silverlight Conditional Styles
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.
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.
精彩评论