安化建設(shè)局網(wǎng)站微信營銷策略有哪些
問題:wpf中,<Button IsEnabled="{Binding IsValid1}"></Button>
,如果沒定義綁定的屬性IsValid1,可以正常用嗎
解答:在 WPF 中,如果沒有定義綁定的屬性 IsValid1,會導(dǎo)致綁定失敗,從而使 Button 的 IsEnabled 屬性無法正常綁定。在這種情況下,Button 的 IsEnabled 屬性將保持默認值,即為 true。
另外,錯誤信息會在vs運行時,在輸入中體現(xiàn):
System.Windows.Data Error: 12 : TargetNullValue '屬性不存在' (type 'String') cannot be converted for use in 'IsEnabled' (type 'Boolean'). BindingExpression:Path=IsValid1; DataItem=null; target element is 'Button' (Name=''); target property is 'IsEnabled' (type 'Boolean') FormatException:'System.FormatException: 屬性不存在 不是 Boolean 的有效值。 ---> System.FormatException: 該字符串未被識別為有效的布爾值。在 System.Boolean.Parse(String value)在 System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)--- 內(nèi)部異常堆棧跟蹤的結(jié)尾 ---在 System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)在 System.Windows.Data.BindingExpressionBase.ConvertValue(Object value, DependencyProperty dp, Exception& e)'