首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

ListBox如何改变选中item的颜色

2013-07-04 
ListBox怎么改变选中item的颜色在windows phone的ListBox中,不修改后台代码,在xaml中能修改选中Item的背景

ListBox怎么改变选中item的颜色
在windows phone的ListBox中,不修改后台代码,在xaml中能修改选中Item的背景色吗,哪位大侠能给出方法,这个问题困扰了我很久,搞得我睡觉都睡不好。
[解决办法]
你可能需要改控件模版
[解决办法]
you need to use MS Blend to modify the ControlTemplate of ListBox

install a Blend first and open a new WP7/8 project, drag drop a ListBox, right click the ListBox, choose "Modify Template"

not very easy if you just a beginner, I suggest just use the default setting


[解决办法]

引用:
cuit 版主
有什么具体点的方法不,或出点代码

不知道WP的ListBox跟WPF的差别大不大。
WPF的可以这样改:

<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid SnapsToDevicePixels="true">
<Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
<ControlTemplate.Triggers>

<!-- 这里更改你想要的颜色 -->
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="" TargetName="Border"/>
</Trigger>

</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

或者

<Style TargetType="ListBoxItem">
        <Style.Resources>
            <!--这里更改你想要的颜色-->
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color=""/>
        </Style.Resources>
    </Style>

热点排行