【发布时间】:2013-04-25 15:02:23
【问题描述】:
我是 WPF 新手;我有一个包含扩展器的列表框(扩展器周围有边框):
<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,它是执行此类操作的非常好的工具
-
触发器需要一个条件来评估,你想要什么条件。触发器是基于数据值还是仅在选择或展开该行/项目时触发?