tags:

views:

44

answers:

2

How can I check the empty string in triggers

<Trigger Property="Source" SourceName="ControlName"  Value="">
     <Setter Property="Height" Value="0" TargetName="ControlName" />
</Trigger>

I have set the Height of the Control to 0 if the source of the imageControl is empty string or not set? How can I do it, Basically If the image is not set then I want to hide the image control in the template.

Thanks in advance.

+1  A: 

If the property isn't set, its value will be null. To specify null in XAML you use a markup extension:

<Trigger Property="Source" SourceName="ControlName"  Value="{x:Null}">
     <Setter Property="Height" Value="0" TargetName="ControlName" />
</Trigger>

HTH,
Kent

Kent Boogaart
thanks for your comments , but I want to check for empty string, mean "" or string.Empty, how can I check it?
Asim Sajjad
The `Source` property is not a `string`, it's an `ImageSource`, so what you're trying to do doesn't make sense.
Kent Boogaart
Suppose that we have controls like textblock, label wich has content or Text property which is of type string. then how can we check?
Asim Sajjad
Exactly as you were checking. I don't believe there's any need to explicitly specify `string.Empty`, but I could be wrong.
Kent Boogaart
+1  A: 

Kent is correct that the Source is not a string but if you do have a sting property to check against you can use the static String.Empty value:

Value="{x:Static sys:String.Empty}"

and the sys namespace declared as

xmlns:sys="clr-namespace:System;assembly=mscorlib"
John Bowen