2010-11-14 68 views
4

我有有TargetNullValue数据绑定按钮:“无”。Silverlight 4中TargetNullValue到资源

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

这工作正常,而当NextItem为null,该按钮显示但我想要将空值绑定到某个东西。

为了简化起见,我们假设我有一个返回值,我想绑定到时候空字符串名为NullValue属性在我的ViewModel属性:

<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}}}" /> 

这也引发同样的异常。有什么建议么?

回答