Why can't I bind data to a field?

I just found out (the hard way) that data binding does not work with fields. This is not a problem considering how easy the automatic properties are, but I was wondering why this is so. Can someone explain?

+3
source share
2 answers

I found a good explanation here :

... because public fields are not recommended. Although they may be convenient for quick and dirty code, they are not versions. Using properties instead allows you to change the access logic and storage data behind covers, as well as add validation logic when a value is assigned. In addition, access properties feel almost the same, and have no performance overhead.

+7
source

Actually, if you use a custom descriptor , you can bind to fields. But I would not recommend it

But data binding is designed as 2-way; with a field, notification of this is not possible.

+1
source

Source: https://habr.com/ru/post/1702300/


All Articles