First I search here and on web and I find many and many solution how change background color of selected item in listbox in WPF but not how do it in windows store app. This framework is litte different I cant get to work any solution.
I use this: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/91575930-2058-413a-99de-f3b31c74dfd9/change-itemtemplate-forground-when-listbox-is-focused?forum=winappswithcsharp on the end of page is very good solution but he set item teplate like this:
ItemTemplate="{StaticResource DataTemplate1}"
but my listbox has datateplate so I dont know how set ItemTemplate style via setter or any different way.
My listbox:
<ListBox x:Name="lbMenu" ItemsSource="{Binding MyDataForLunchGrid}" Tapped="lbMenzaMenu_Tapped" Style="{StaticResource ListBoxStyle1}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Style" Value="{StaticResource ListBoxItemStyle1}"/>
</Style>
</ListBox.ItemContainerStyle >
<ListBox.ItemTemplate >
<DataTemplate>
<Grid>
<TextBlock Foreground="#FF19536E" x:Name="tbMenu" Text="{Binding launchItemName}"/>
<TextBlock x:Name="tbMenuNumber" Text="{Binding launchNumber}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Now when I press any item in listbox its have dark violet(default) color and its look horible.
Best Answer
I think you want to change the definition of your
ItemContainerStyle
. Try something like this:The resource "ListBoxItemStyle1" should contain the control template for
ListBoxItem
:The control template in turn defines the "Selected" visual state. From the page you linked, "ListBoxItemStyle1" defines that visual state as follows (yellow background):
Note that, by default, the ListBoxItem's "selected" state uses as its background the user's current "accent brush", as seen below. This is probably the source of the dark violet color that you see. (You can find all default styles and templates in the Windows Phone SDK folder.)
You can modify this as needed -- copy-paste a default style, either from the Windows SDK, or from the linked page, and set the background and other properties to whatever you want.
For more background info on control templates and visual states, see Customizing the Appearance of an Existing Control by Using a ControlTemplate.