Reputation: 1138
I have the following listbox:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,10,0,10">
<TextBlock
Foreground="Black"
Text="{Binding name}"/>
<TextBlock
Foreground="Black"
Text=": "
Visibility="{Binding
Path=name,
Converter={StaticResource ServiceOtherConverter}}"/>
<TextBlock
Foreground="Black"
Text="{Binding amount}"
Visibility="{Binding
Path=name,
Converter={StaticResource ServiceOtherConverter}}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And my app has a white background, so I'd like to set the list items foreground to black. But when I select an item, its foreground doesn't change, as it does whith the default foreground.
How can I change the list items foreground to black but still have the selected foreground different?
Upvotes: 1
Views: 3341
Reputation: 23280
You just need to change the Foreground in the Selected VisualState at the style template level for the ListBox Item. For reference you might peek at the msdn doc for ListBox Styles and Templates. Expression Blend makes it pretty painless. Just right-click your item and choose "Edit Additional Templates" and choose the Item template. Then from the States tab, choose the Selected State and change the foreground color. Or you could just do it directly in the template code. Hope this helps.
Upvotes: 1