Windows Phone上的列表框样式选定项 [英] ListBox Style Selected item on windows phone
问题描述
我想知道我可以在选择列表框中的项目添加一个样式. 我有以下列表框:
i would like know how can i add a style when a item of the listbox is selected. I have the following listbox:
<ListBox x:Name="ListBoxDays"
VerticalAlignment="Top"
ItemTemplate="{StaticResource WeekDayTemplate}"
ItemsSource="{Binding WeekDayList}" />
我在列表框中也有一个DataTemplate.
And i also have a DataTemplate to the listbox.
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="WeekDayTemplate">
<StackPanel x:Name="stackPanel" Orientation="Horizontal" Width="400" Margin="12,0,0,10" Height="100" >
<StackPanel VerticalAlignment="Center" Orientation="Vertical">
<TextBlock Text="{Binding WeekDayName}" Style="{StaticResource PhoneTextExtraLargeStyle}" TextWrapping="Wrap" TextTrimming="WordEllipsis" Foreground="{StaticResource PhoneRadioCheckBoxPressedBorderBrush}" UseLayoutRounding="True" />
<TextBlock Text="{Binding ShortDate}" Style="{StaticResource PhoneTextTitle2Style}" TextWrapping="Wrap" TextTrimming="WordEllipsis" Foreground="{StaticResource PhoneBorderBrush}" Margin="25,0,12,0" />
</StackPanel>
</StackPanel>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
当我选择列表框的项目时,没有发生颜色变化.
At the moment when i select an item of the listbox no color change happens.
推荐答案
您必须更改ListBox
为它呈现的每个项目生成的模板ListBoxItem
的样式.您更新的模板需要自定义选定"视觉状态.然后,您可以通过ListBox.ItemContainerStyle
属性将此新模板与ListBox
关联.
You have to change the style of the template ListBoxItem
which the ListBox
generates for each of the items that it renders. Your updated template needs to customise the Selected visual state. You can then associate this new template with your ListBox
via the ListBox.ItemContainerStyle
property.
这里有一个很好的教程,带有源代码可供下载,
There is a good tutorial, with sourcecode to download, here:
这篇关于Windows Phone上的列表框样式选定项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!