如果数据为空,如何隐藏字符串格式 [英] How to hide stringformat if data is null

查看:56
本文介绍了如果数据为空,如何隐藏字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当不存在数据时如何隐藏字符串格式.请考虑此示例

How to hide a stringformat when data is not present.Consider this sample

<TextBlock Text="{Binding Amount, StringFormat=Total: {0:C}}" />

在这种情况下,如果Amount为null,那么它将仅显示Total:.如果Amount为null或为空,如何隐藏它

in this case if Amount is null,Then it will show just Total:.How to hide this if Amount is null or empty

推荐答案

"TargetNullValue"是我一直在寻找的东西.

"TargetNullValue" is what i was looking for.I ended up with this and it worked like a charm

<TextBlock VerticalAlignment="Top"
             Text="{Binding Path=TotalMonths,
        TargetNullValue={x:Static System:String.Empty},
        StringFormat=Total: {0:C}}" />

这篇关于如果数据为空,如何隐藏字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆