更改样式中的复选框不透明度不起作用

时间:2023-01-12 19:36:10

I have a disabled CheckBox that I want to change the Opacity through a Style when IsChecked is True.

我有一个禁用的CheckBox,我想在IsChecked为True时通过样式更改不透明度。

Issue: Opacity is not changing.

问题:不透明度没有变化。

<Style TargetType="{x:Type CheckBox}">
                <Setter Property="IsChecked"
                        Value="False" />
                <Style.Triggers>
                    <Trigger Property="IsChecked"
                             Value="True">
                        <Setter Property="CheckBox.Opacity"
                                Value="1.0" />
                   </Trigger>
                </Style.Triggers>
</Style>


<CheckBox  IsChecked="{Binding IsChecked, Mode=OneWay}" IsEnabled="False"/>

1 个解决方案

#1


0  

You're setting the Opacity to 1.0 (100% opaque), which is the default. That is why you don't see any change when the checkbox is checked. If you set your value to something between 0.0 and 1 (0.5 for example), you'll see the opacity change when the checkbox is checked.

您将不透明度设置为1.0(100%不透明),这是默认值。这就是选中复选框时看不到任何更改的原因。如果将值设置为介于0.0和1之间(例如0.5),则会在选中复选框时看到不透明度更改。

#1


0  

You're setting the Opacity to 1.0 (100% opaque), which is the default. That is why you don't see any change when the checkbox is checked. If you set your value to something between 0.0 and 1 (0.5 for example), you'll see the opacity change when the checkbox is checked.

您将不透明度设置为1.0(100%不透明),这是默认值。这就是选中复选框时看不到任何更改的原因。如果将值设置为介于0.0和1之间(例如0.5),则会在选中复选框时看到不透明度更改。