tags:

views:

86

answers:

2

I've just learnt (the hard way) that databinding doesn't work with fields. This isn't a problem given how easy automatic properties are, but I was wondering why this is the case. Can anyone explain?

+7  A: 

I found a good explanation here:

... because public fields are not a recommended practice. While they maybe convenient for quick and dirty code, they do not version. Using properties instead allows you to change the access logic, and data storage behind the covers, as well as add validation logic when a value is assigned. Furthermore, accessing properties feels pretty much the same, and do not have any performance overhead.

bruno conde
+1  A: 

Actually, if you use a custom descriptor, you can bind to fields. But I wouldn't recommend it

But data-binding is designed t be 2-way; with a field, there is no notification possible.

Marc Gravell