DataTrigger does not change Text property

后端 未结 1 1685
北海茫月
北海茫月 2020-11-27 23:21

I\'m attempting to use a data-trigger on a style to change a property.

In compliance with the \"Minimal, Complete and Verifiable Example\" requirements...

T

相关标签:
1条回答
  • 2020-11-28 00:24

    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.

    0 讨论(0)
提交回复
热议问题