I have the following item template in a WP7 listbox. My bound type has a boolean property (Status) and I would like to conditionally set the colour of the site name based on this. How would I go about doing this please?
Thanks in advance!
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<TextBlock Text="{Binding SiteName}" TextWrapping="Wrap" />
<TextBlock Text="{Binding Url}" TextWrapping="Wrap" Margin="12,-6,12,0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
The easiest way to do this is with a converter. Either you can have the converter return a color, or you can have two TextBlocks each with the color you want, and use a Boolean to Visibility, and one that is a reverse visibility, converters to hide/show each of the controls.
One word of caution is that converters can be slow, so sometimes it’s more performant to bind to a ViewModel and on that ViewModel provide the convetered values that you need.