我已经尝试了此站点上的不同示例,以使列表框/复选框组合在选择时从默认灰色更改为另一种颜色,但无济于事。
我最终要做的是,如果选中该项目,则背景将为白色,未选中时它将变灰。
这是我所拥有的,任何帮助将不胜感激。
将资源更新为下面的评论。
控件已更新到回复,但仍然无法正常工作,有什么想法吗?
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemsSource="{Binding}"
Name="lstSwimLane" SelectionMode="Multiple"
Width="auto"
Height="auto"
Background="Transparent"
BorderThickness="0"
SelectionChanged="LstSwimLaneSelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding Path=IsChecked, Mode=TwoWay}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="Border" SnapsToDevicePixels="true">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBrush}"/>
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="Background" Value="{StaticResource UnselectedBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="3,3,3,3">
<CheckBox IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}"
Checked="ChkFilterChecked"
Unchecked="ChkFilterUnchecked"
VerticalAlignment="Center"
Margin="0,0,4,0" />
<TextBlock Text="{Binding Value}" VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
注意:选中的复选框和列表项组合仍为灰色,未选中的为白色。
附件是一个屏幕截图,似乎与下面的回复相匹配。我难住了。
这是直接链接,以便查看更大的图像。
http://s1120.photobucket.com/albums/l489/nitefrog/?action=view¤t=jw_0012011-03-311325.jpg
这是复选框的屏幕截图。
http://i1120.photobucket.com/albums/l489/nitefrog/jw_0022011-03-311345.jpg
即使设置了画笔,由于某种原因,它们也没有被触发。
有任何想法吗?
谢谢。