問題:wpf中,<Button IsEnabled="{Binding IsValid1}"></Button>
,如果沒定義綁定的屬性IsValid1,可以正常用嗎文章來源:http://www.zghlxwxcb.cn/news/detail-677637.html
解答:在 WPF 中,如果沒有定義綁定的屬性 IsValid1,會導(dǎo)致綁定失敗,從而使 Button 的 IsEnabled 屬性無法正常綁定。在這種情況下,Button 的 IsEnabled 屬性將保持默認(rèn)值,即為 true。
另外,錯誤信息會在vs運(yùn)行時,在輸入中體現(xiàn):文章來源地址http://www.zghlxwxcb.cn/news/detail-677637.html
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)'
到了這里,關(guān)于WPF如果未定義綁定的屬性,程序如何處理的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!