Herrozerro
Herrozerro

Reputation: 1681

Databinding and property datatype

Quick question. I understand how properties work with the get and set methods, but how should I be using them when bound to textboxes.

Should all of my properties be strings and then validated from there to my fields which may be of different types? What would happen if a alpha character was put into a textbox bound to an int type field? does it throw exceptions at that time or If I validate it would it be alright?

thanks!

Upvotes: 1

Views: 59

Answers (1)

blindmeis
blindmeis

Reputation: 22435

if all your viewmodel properties are strings then you have no trouble to bind and validate your properties. but of course you have to cast them for your model, but its the most easy way for viewmodel and binding :)

just do a litte test project.

viewmodel:

 public string MyStringInt {get;set}
 public int MyIntInt {get;set;}

just try to implement IDataErrorInfo for this easy viewmodel and you will see the problems when binding to an int property.

Upvotes: 1

Related Questions