如果数据为空,如何隐藏字符串格式

发布于 2024-09-19 06:09:45 字数 174 浏览 2 评论 0原文

当数据不存在时如何隐藏字符串格式。

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

在这种情况下考虑此示例,如果金额为空,那么它将只显示总计:。如果金额为空或空,如何隐藏它

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

葬花如无物 2024-09-26 06:09:46

您要么必须实现某种值转换器(示例),要么考虑在绑定上使用 TargetNullValue 属性(示例< /a>)

You either have to implement some sort of value converter (Example) or consider using the TargetNullValue property on the binding (Example)

若水般的淡然安静女子 2024-09-26 06:09:46

“TargetNullValue”就是我一直在寻找的。我最终得到了这个,它就像一个魅力

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

"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}}" />
哭泣的笑容 2024-09-26 06:09:46
TargetNullValue=''

也会做

TargetNullValue=''

Will do also

眼藏柔 2024-09-26 06:09:46

这里没有太多需要处理的内容,但您可以通过以下方式实现类似的功能:

  • DataTrigger
  • ValueConverter
  • EventHandling in Code-Behind
  • Binding on a (dependency-)property in a ViewModel encapsuling yourbusiness Class

There's not much to work with here, but you can achieve something like this with:

  • DataTrigger
  • ValueConverter
  • EventHandling in Code-Behind
  • Binding on a (dependency-)property in a ViewModel encapsulating your business classes
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文