【问题标题】:Why TargetNullValue cannot be used in x:Bind?为什么 TargetNullValue 不能在 x:Bind 中使用?
【发布时间】:2017-03-04 19:25:08
【问题描述】:

作为MSDN saysTargetNullValue

指定当源值解析但显式为空时显示的值。

使用旧的绑定,这样的事情是可能的并且有效:

<Grid Visibility="{Binding Something, Converter={StaticResource myconv}, TargetNullValue='Collapsed'}">

x:Bind 不可能 - 如果我们写:

<Grid Visibility="{x:Bind Something, Converter={StaticResource myconv}, TargetNullValue='Collapsed'}">

我们可能会得到错误:

TargetNullValue 不能应用于“可见性”,因为其类型“可见性”不可为空。

这对我来说没有多大意义 - 为什么会这样?

【问题讨论】:

  • 你必须在转换器中处理空值。
  • @TóthTibor 是的,用转换器处理它是我已经在做的事情,它只是让 TargetNullValue 无用,因为你不能使用它,而它显然应该是可能的。
  • 你仍然可以在 uwp 中使用 Binding

标签: c# xaml uwp uwp-xaml


【解决方案1】:

这对我来说没有多大意义 - 为什么会这样?

根据documentation{x:Bind} 缺少{Binding} 的一些功能”,显然这是其中之一。

显然TargetNullValue 不能为 value 类型的目标属性指定。

但是您可以在转换器中轻松处理此问题,因此这应该是一个很大的问题。

如果您愿意,您可以随时在 UserVoice 提出此问题:https://wpdev.uservoice.com/forums/110705-universal-windows-platform

【讨论】:

  • 这就是我所害怕的,尽管它并没有改变它对我来说没有意义的事实。不过,我有posted on UserVoice
猜你喜欢
  • 2016-03-06
  • 2016-07-23
  • 2019-05-16
  • 2020-08-20
  • 1970-01-01
  • 2021-05-12
  • 1970-01-01
  • 2016-12-12
  • 2020-01-02
相关资源
最近更新 更多