OK, working on WPF (using MVVM) and faced with a question, I want to contribute. I have a simple class
as shown below (suppose I have IDataErrorInfo):
public class SimpleClassViewModel { DataModel Model {get;set;} public int Fee {get { return Model.Fee;} set { Model.Fee = value;}} }
Then I try to bind it to xaml:
<TextBox Text={Binding Fee, ValidatesOnDataErrors=true}/>
when the user deletes the text, a data binding error occurs because he cannot convert string.empty to int. Well, the board is a required field, but since the data binding will not convert back, I cannot provide error information because my class is not updated. So, I have to do the following:
public class SimpleClassViewModel { DataModel Model {get;set;} int? _Fee; public int? Fee { get { return _Fee;} set { _Fee = value;if (value.HasValue) { Model.Fee = value;} } }
source share