开发者

WPF/Silverlight Conditional Styles

开发者 https://www.devze.com 2022-12-21 07:43 出处:网络
Given the object graph below I need to have 2 different style applied depending on whether开发者_如何转开发 the Parent object has any children or not.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消