我有一个ListBox(SurfaceListBox),当元素在特定属性上为false时,我需要更改元素的文本颜色。
查看我的代码,这很好用:
<DataTrigger Binding="{Binding IsSelectable}" Value="False">
但使用以下方式设置颜色:
<Setter Property="Foreground" Value="Black"/>
不起作用,颜色不会改变。
任何想法如何解决它,或另类approch?
<Style x:Key="CategorySurfaceListBoxItemStyle"
TargetType="{x:Type Custom:SurfaceListBoxItem}"
BasedOn="{StaticResource ControlBaseStyle}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Custom:SurfaceListBoxItem}">
<Grid
x:Name="Grid"
Background="{StaticResource ControlHitAreaBrush}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
<ContentPresenter x:Name="Content" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- Disable dot items -->
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelectable}" Value="False">
<Setter Property="IsEnabled" Value="False"/>
<Setter Property="Foreground" Value="Black"/> <!--PROBLEM HERE-->
</DataTrigger>
</Style.Triggers>
</Style>
答案 0 :(得分:0)
我能够以这种方式解决问题:
使用 以下代码:
<Style.Triggers>
<!-- Disable dot items and style -->
<DataTrigger Binding="{Binding IsSelectable}" Value="False">
<Setter Property="IsEnabled" Value="False"/>
<Setter Property="Foreground" Value="Black"/>
</DataTrigger>
<!-- Enable other elements and style -->
<DataTrigger Binding="{Binding IsSelectable}" Value="True">
<Setter Property="IsEnabled" Value="True"/>
<Setter Property="Foreground" Value="#1799c3"/>
</DataTrigger>
</Style.Triggers>