2010-11-14 32 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}}}" /> 

這也引發同樣的異常。有什麼建議麼?

回答