[ACCEPTED]-How to make a text box Visibility=Hidden with a trigger-datatrigger

Accepted answer
Score: 24

You need to set the Style.TargetType in order for it to 1 recognize the Visibility property:

<TextBlock Grid.Column="2" VerticalAlignment="Center" FontWeight="Bold" Foreground="Red" Padding="5" Text="This order will be sent to accounting for approval">
        <Style TargetType="{x:Type TextBlock}">
                <DataTrigger Binding="{Binding Path=AllowedToSubmit}" Value="True">
                    <Setter Property="Visibility" Value="Hidden"/>

Your binding path to AllowedToSubmit probably needs to have ElementName set to the Window's name, as well.

Score: 8

Another option is to bind TextBlock.Visibility directly to the 4 property:

        <BooleanToVisibilityConverter x:Key="BoolToVisibility" />
    <TextBlock Visibility="{Binding Path=AllowedToSubmit, Converter={StaticResource BoolToVisibility}}" />

If you want it to work like in 3 your sample, where true hides the TextBlock, then 2 you can write your own converter to convert 1 opposite of the built-in BooleanToVisibilityConverter.

More Related questions