[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">
    <TextBlock.Style>
        <Style TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=AllowedToSubmit}" Value="True">
                    <Setter Property="Visibility" Value="Hidden"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>

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:

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

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