我是一名进入 .Net 的 Access 开发人员,我有一个 WPF 项目。由于我习惯于 Access 中的子表单,因此我创建了用户控件以这种方式进行操作(本身可能是一个问题,但我目前还没有解决这个问题)。
这个特定的用户控件(子窗体)有几个列表框,这些列表框绑定到后面代码中的对象(VB——我也没有参与那个辩论;我熟悉 VBA)。这些列表框绑定到一个名为“IsAssigned”的布尔值。我创建了一种样式,根据该值将这些列表框中的项目更改为绿色或红色。这是有效的。
然后我想更改该值以覆盖窗口的突出显示行为并了解 SystemColors.HighlightColor 和 ControlBrushKey。问题是我希望 HighlightColor 和 ControlBrushKey 颜色取决于“IsAssigned”值。除非我错过了什么,否则我显然无法嵌套触发器。在下面的代码中,我将高亮值设置为绿色只是为了说明我对此的理解。
So what I want is that when an item is selected, the text is bolded, with a black border, and maintains a solid color of green or red depending on the "IsAssigned" value. 当同一个项目是突出显示的项目时,我真的希望前景色为白色,并且可能有更厚的边框。
温柔点——我在很多方面都是菜鸟。
<UserControl.Resources>
<Style TargetType="{x:Type ListBoxItem}" x:Key="ColorTrueAndFalse">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightColor}" Color="Green" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Green" />
</Style.Resources>
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="BorderBrush" Value="Black" />
</Trigger>
<DataTrigger Binding="{Binding IsAssigned}" Value="True">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="LightGreen" Offset="0" />
<GradientStop Color="Green" Offset="1" />
<GradientStop Color="LawnGreen" Offset="2" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding IsAssigned}" Value="False">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="LightCoral" Offset="0.5" />
<GradientStop Color="Coral" Offset="1" />
<GradientStop Color="Red" Offset="2" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>