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.
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"
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>
精彩评论