Reputation: 6653
I have a page which is databound to an object like so this.DataContext = anObject;
, the properties of that object binds perfectly.
But now I have a control within that.
<Control2></Control2>
And in the constructor for that control I set this.DataContext = anotherObject;
The problem I seem to be having when I do this is that this Control2 seems to be double bound when I do {Binding aProperty}
it complains about it not being in anotherObject
and when I bind {Binding anotherProperty}
it'll complain about it not having it in anObject
Any ideas.
Upvotes: 0
Views: 71
Reputation: 21251
I suspect the data context is being set by the page after you've set it in the constructor. Thus you're getting two different binding sources reported at different times.
Try listening to the DataContextChanged event in your control.
Upvotes: 1