【发布时间】:2010-10-26 11:27:12
【问题描述】:
我有一个ListBox,上面有一些图片。我想用某种颜色突出显示所选项目。我正在使用WwrapPanel 以ScrollViewer 水平显示图像。有什么办法可以解决我的问题吗?
【问题讨论】:
-
也许想检查这个问题的标题的拼写和语法
标签: c# wpf xaml listbox selecteditem
我有一个ListBox,上面有一些图片。我想用某种颜色突出显示所选项目。我正在使用WwrapPanel 以ScrollViewer 水平显示图像。有什么办法可以解决我的问题吗?
【问题讨论】:
标签: c# wpf xaml listbox selecteditem
这应该可以解决问题:
<Window x:Class="StackOverflowTests.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" x:Name="window1" Height="300" Width="300">
<Window.Resources>
<!-- Specifies the Selection style of ListBoxItems. This changes the forced underlay colors from gray to transparent. -->
<Style TargetType="ListBoxItem">
<Style.Resources>
<!-- This is the color used if the item is selected and the listbox has focus -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
</Style.Resources>
</Style>
</Window.Resources>
<Grid>
<StackPanel Orientation="Vertical">
<ListBox>
<ListBoxItem Content="Item 1" />
<ListBoxItem Content="Item 2" />
<ListBoxItem Content="Item 3" />
<ListBoxItem Content="Item 4" />
<ListBoxItem Content="Item 5" />
<ListBoxItem Content="Item 6" />
<ListBoxItem Content="Item 7" />
<ListBoxItem Content="Item 8" />
<ListBoxItem Content="Item 9" />
<ListBoxItem Content="Item 10" />
</ListBox>
</StackPanel>
</Grid>
</Window>
【讨论】:
您应该在 IsSelected 属性上使用带有触发器的 ItemContainerStyle,并在 Trigger 中将 setter 放在 Background 属性上
【讨论】: