'The member “Opacity” is not recognized or is not accessible.' Why can't I set the opacity?

只谈情不闲聊 提交于 2020-01-30 05:48:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!