So I have this little problem making this to work:
- I have silverlight client app that has custom usercontrol with tri-state checkbox with two-way binding
-
After user changes checkbox value, function underlying the property translates the value to integer:
-1 nothing 0 false 1 true -
After user saves data from dialog box, all data(complex object) is being serializes and sent over to webservice and stored in SQL db.
- When client requests saved data back from webservice, it get back that object OK
-
When I try to bind that returned deserialized object(EA) back to checkbox like this:
With cC Dim b As New Binding("AllowedTo.Create") b.Source = EA b.Mode = BindingMode.TwoWay .SetBinding(CheckBox.IsCheckedProperty, b) End With
it only works ok if the values are true or false, but if value is nothing, as the checkbox is tri-state, it should turn to that third state – undefined – with minus sign [-], but it dosent.
It just stays at false state – empty with no check, like it would be false.
What could be the problem?
Sorry for my english, its not my mother language
Don’t use an integer for this, use a Nullable Bool (Bool?). Two way binding works well, it converts:
Serialization isn’t a problem with nullable bools, in fact you don’t even have to check if the SQL field value is NULL, since it will be a valid state, and using a bool field in the SQL database will even reduce it’s size a bit 😉
If your database is set, and you can’t change it, write a converter to convert your integer to a nullable bool for the binding, shouldn’t take more then 2 minutes.