Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty String Check in Trigger

Tags:

wpf

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.

like image 445
Asim Sajjad Avatar asked Apr 05 '10 09:04

Asim Sajjad


2 Answers

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"
like image 177
John Bowen Avatar answered Nov 02 '22 22:11

John Bowen


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>
like image 6
Kent Boogaart Avatar answered Nov 02 '22 22:11

Kent Boogaart