问题
I would like to use a DataTrigger to modify the opacity of my button.
<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>
I know that a Button has an Opacity you can set, and that DataTriggers must be used in a Style. However the compiler is reporting 'The member "Opacity" is not recognized or is not accessible.' What am I doing wrong?
回答1:
You should add 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>
...
来源:https://stackoverflow.com/questions/42122424/the-member-opacity-is-not-recognized-or-is-not-accessible-why-cant-i-set-t