tags:

views:

14

answers:

1

I have a style applied to a TextBox. The style contains two triggers - both of which check the property Validation.HasError. A different image is displayed on the background of the TextBox indicating if the data is valid or not.

I'm trying to change the style so that when the TextBox is empty, no image is displayed in the background. I was hoping to find another property to use in the trigger that would allow me to check if it is empty or not, but I can't find one.

Am I going about this the wrong way? Here is the style as it is currently:

<Style x:Key="ValidationTextBox" TargetType="TextBox">
    <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="false">
            <Setter Property="TextBox.Background">
                <Setter.Value>
                    <ImageBrush ImageSource="fieldWhite_check.png" AlignmentX="Right" AlignmentY="Top" Stretch="None" />
                </Setter.Value>
            </Setter>
        </Trigger>          
        <Trigger Property="Validation.HasError" Value="true">
            <Setter Property="TextBox.Background">
                <Setter.Value>
                    <ImageBrush ImageSource="fieldWhite_error.png" AlignmentX="Right" AlignmentY="Top" Stretch="None" />
                </Setter.Value>
            </Setter>
        </Trigger>
    </Style.Triggers>
</Style>
A: 

You have multiTrigger, so you can check for the value to be Empty "" or to be null {x:Null} and keep checking for the HasError property http://en.csharp-online.net/WPF_Styles_and_Control_Templates%E2%80%94Multi-Condition_Property_Trigger

jmayor
Err, I'm such an idiot. That is really obvious. For some reason I was looking for a boolean value to check against. I think I need a coffee to wake me up. Thanks!
Sio