1
我是WPF新手;我有一个包含扩展(扩展器有他们周围的边框)列表框:更改ListBoxItem内容的背景颜色
<ListBox Background="Transparent" BorderBrush="Transparent">
<ListBox.Style>
<Style>
<Style.Resources>
<!-- Background of selected item when focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<!-- Background of selected item when not focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</Style.Resources>
</Style>
</ListBox.Style>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Margin="5" BorderThickness="2" BorderBrush="LightGray" CornerRadius="5">
<Expander IsExpanded="True" Background="#f7f7f7">
<!-- Content -->
</Expander>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
我想的行为所选择的项目有其展开的背景颜色变深(例如#e0e0e0)。我找到了让我隐藏ListBoxItem的背景颜色(这在代码中显示)的示例,但是没有好的方法来更改ListBoxItem中内容的背景颜色。我知道我需要设置一个触发器来执行此操作,但我不知道如何设置它,无论它是ListBox还是Expander的触发器。
如何设置适当的触发器?
你可能想尝试Expression Blend中,这是非常好的工具,做这样的事情 – 2013-04-25 15:14:50
触发器需要评估的条件,你要什么条件。是基于数据值的触发器,还是仅仅在选择或扩展该行/项目时? – 2013-04-25 15:15:20