在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
------解决方案--------------------
不知道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>