DataTrigger does not change Text property

强颜欢笑 提交于 2019-11-26 21:04:08

The local value assigned to the TextBlock's Text property has higher precedence than the value provided by the Setter in the DataTrigger. See Dependency Property Value Precedence for details.

Set the initial Text value by another Setter:

<TextBlock>
    <TextBlock.Style>
        <Style TargetType="TextBlock">
            <Setter Property="Text" Value="Unclicked"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Clicked,
                                       Source={x:Static Application.Current}}"
                             Value="{StaticResource True}">
                    <Setter Property="Text" Value="Clicked" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>

The error message you see when you use the Boolean resource is just the XAML designer complaining. There is no error at runtime.

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