【问题标题】:Silverlight 4 TargetNullValue to ResourceSilverlight 4 TargetNullValue 到资源
【发布时间】:2010-11-14 22:04:39
【问题描述】:

我有一个具有 TargetNullValue 的数据绑定按钮:

<Button Content="{Binding Path=NextItem, Mode=OneWay, TargetNullValue='None'}" />

效果很好,当 NextItem 为空时,按钮显示“无”。但我想将 null 值绑定到某个东西。

为了简单起见,假设我的 ViewModel 上有一个名为 NullValue 的属性,它返回一个字符串,当它为 null 时,我希望绑定到该字符串:

<Button Content="{Binding Path=NextItem, Mode=OneWay, TargetNullValue={Binding Path=NullValue}}" />

但这会引发:

System.Windows.Markup.XamlParseException: Provide value on 'System.Windows.Data.Binding' threw an exception. [Line: 129 Position: 92] 
---> System.InvalidOperationException: Operation is not valid due to the current state of the object.
at MS.Internal.XamlManagedRuntimeRPInvokes.TryApplyMarkupExtensionValue(Object target, XamlPropertyToken propertyToken, Object value)
at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue)

我真正想做的是将 null 值绑定到 resx,所以我在控件的资源字典中有它,并像这样更改绑定:

<res:AppResources x:Key="appResources" />
...
<Button Content="{Binding Path=NextItem, Mode=OneWay, TargetNullValue={Binding Path=NullValue,Source={StaticResource appResources}}}" />

这也会引发相同的异常。有什么建议吗?

【问题讨论】:

    标签: data-binding silverlight-4.0 resources


    【解决方案1】:

    我在 Connect 上为此创建了一个问题。如果有人遇到此问题,请投票支持该错误。

    https://connect.microsoft.com/VisualStudio/feedback/details/632602/silverlight-4-targetnullvalue-binding-to-resource

    【讨论】:

      猜你喜欢
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多