1

If I have a WPF listbox and I bind its itemssource to a list of objects. If the object members are public but don't have a { get; set; } the binding will fail. Why?

H.B.
  • 166,899
  • 29
  • 327
  • 400
patrick
  • 16,091
  • 29
  • 100
  • 164
  • 2
    Actually a getter is enough unless you want to bind both ways. – H.B. Jun 02 '11 at 21:36
  • Does this answer your question? [Why does WPF support binding to properties of an object, but not fields?](https://stackoverflow.com/questions/842575/why-does-wpf-support-binding-to-properties-of-an-object-but-not-fields) – Peter Duniho Mar 19 '20 at 03:11

2 Answers2

8

I think what you're really asking is "Why do I have to use properties instead of just fields?" And the answer is that that's just how WPF bindings work. You have to bind to properties on objects. The binding system doesn't look for matching fields.

Tim
  • 14,999
  • 1
  • 45
  • 68
4

The binding is looking specifically for Properties, not fields. That's why bindings work on PropertyPath objects.

Tejs
  • 40,736
  • 10
  • 68
  • 86