Windows Phone上的列表框样式选定项 [英] ListBox Style Selected item on windows phone

查看:77
本文介绍了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:

http://windowsphonegeek.com/tips/How-to-customize-the-WP7-ListBox-Selected-Item--Part1-Control-Template

这篇关于Windows Phone上的列表框样式选定项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆