質問

I have a ListBox that contains a StackPanel with elements for binding. Based on a value, for instance 'Overdue' = true, the style of the StackPanel and a few elements below should change. The only difference between each item is the background of the StackPanel and the Foreground of two TextBlocks would change. I thought about creating a separate template for each, but with 20 options, that seems like overkill. I have a SolidColorBrush setup for each of the 20 items.

I thought I could use a DataTrigger, but I read somewhere that they are not supported in WP7 as WP7 supports Silverlight 3 and greater.

I'm looking for suggestions. I apologize that this may seem to be too subjective and hope someone has the best practice for this situation.

役に立ちましたか?

解決

You should consider using a ValueConverter that return SolidColorBrush based on the item's DataContext.

Take a look at Tim's blog, for code sample and detailed explanation.

http://timheuer.com/blog/archive/2008/07/30/format-data-in-silverlight-databinding-valueconverter.aspx

Hope this helps.

Code From Home Dev

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top