我在这里和网络上搜索了很多关于如何更改WPF Listbox中所选项的背景颜色的解决方案,但没有找到关于如何在Windows Store应用程序中实现的方法。该框架与其他框架略有不同,我无法使任何解决方案正常工作。
我使用了这个:http://social.msdn.microsoft.com/Forums/windowsapps/en-US/91575930-2058-413a-99de-f3b31c74dfd9/change-itemtemplate-forground-when-listbox-is-focused?forum=winappswithcsharp 本页末尾提供了一个非常好的解决方案,但他将项目模板设置为:
ItemTemplate="{StaticResource DataTemplate1}"
而我的ListBox具有DataTemplate,因此我不知道如何通过setter或任何其他方式设置ItemTemplate样式。
我的列表框:
<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>
现在,当我按下列表框中的任何项时,它们都呈现出深紫色(默认)颜色,看起来很糟糕。