Bob Sammers
Bob Sammers

Reputation: 3280

Default binding when Source and DataContext are not specifed

I'm trying to get to grips with some of the nuances of data binding in WPF. I understand that one may specify a source directly on the binding (using Source, RelativeSource, etc.) or rely on a DataContext within the target's object hierarchy such that the first set value of DataContext encountered traversing the target's ancestors provides the source for any bindings.

What I haven't been able to work out is what happens if the source is not set in some way (i.e. the DataContext has not been explicitly set anywhere in the target's ancestry and the binding only specifies a Path).

  1. Where (if anywhere) does the binding engine look for the source property specified in Path?
  2. Why do I not seem to get any error in the VS "Output" window if the binding fails in this situation (binding errors are normally shown here)?

(.net 4.5, VS 2012 RC, Win 7 32-bit)

Upvotes: 0

Views: 99

Answers (1)

hbarck
hbarck

Reputation: 2944

What happens is that your binding doesn't bind to anything. That's not a binding error, since you don't have to set DataContext explicitly (it is inherited from other elements further up the logical tree), so it is perfectly valid to have a control that waits for its DataContext to be set.

Upvotes: 1

Related Questions