我將我的WPF表單綁定到類的十進制屬性。如果用戶輸入無效格式(字符串而不是十進制),文本框會自動加亮顯示爲紅色。但是,我想通過在將插入的數據存儲到數據庫之前進行驗證來使其更安全。在WPF綁定中設置十進制屬性的默認值
問題是,只要用戶輸入非十進制值,綁定將返回0而不是null或錯誤。所以它設法進入數據庫,沒有二級驗證。
驗證WPF綁定到小數的最佳方法是什麼?現在它不會返回null,所以我沒有任何方法來捕獲錯誤。
這裏是我如何綁定文本框
<TextBox x:Name="stockTxtBx" Grid.Row="3" Grid.Column="1" Style="{StaticResource StandardBox}" Text="{Binding StockOnHand}"/>
另外,我在哪裏可以修改添加驗證?
我敢肯定[此頁](http://stackoverflow.com/questions/7575286/numeric-text-box-with-mvvm-pattern)會幫助你 – Prisoner
@HaikalNashiha [也許谷歌翻譯](https: //translate.google.com.hk/translate?sl=de&tl=en&js=y&prev=_t&hl=zh-TW&ie=UTF-8&u=http%3A%2F%2Fblindmeis.wordpress.com%2F2010%2F06%2F01%2Fwpf- masked-textbox-behavior%2F&edit-text =&act = url) – Prisoner
@HaikalNashiha [本頁同樣適合你](http://rubenhak.com/?p=8) – Prisoner