我想使用DataTrigger来修改我的按钮的不透明度。
<Button x:Name="StartTreatment"
Grid.Column="3"
Width="160"
Height="30"
Content="{x:Static resources:UserMessages.TrcsConsoleViewModel_LoadWfSequence_StartProcedure}"
IsEnabled="{Binding CanStartProcedure}"
Visibility="{Binding CanStartPatientTreatment, Converter={StaticResource BooleanToVisibility}}" >
<Button.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding CanStartProcedure}" Value="False">
<Setter Property="Opacity" Value="0.5"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
我知道Button可以设置不透明度,并且必须在Style中使用DataTriggers。然而,编译器正在报告&#34;成员&#34; Opacity&#34;无法识别或无法访问。&#39;我做错了什么?
答案 0 :(得分:9)
您应该添加TargetType
:
...
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding CanStartProcedure}" Value="False">
<Setter Property="Opacity" Value="0.5"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
...