开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜