Asim Sajjad
Asim Sajjad

Reputation: 2534

Empty String Check in Trigger

How can I check for an empty string in a trigger?

<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.

Upvotes: 18

Views: 15814

Answers (2)

Kent Boogaart
Kent Boogaart

Reputation: 178770

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>

Upvotes: 6

John Bowen
John Bowen

Reputation: 24453

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"

Upvotes: 47

Related Questions