Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm puzzled by the Binding RelativeSource functionality. My question is in several parts:

I want to bind to the data context of the whole window from a control buried deep in the visual tree

1. How do I determine the AncestorLevel?

2. Why should I need to specify this at all when I know there is only ever one window?

3. If I do figure out the AncestorLevel and get it working, doesn't this make the code brittle? If I change the nesting of the controls, it will break.

Any advice would be gratefully received.

What I have tried:

I have tried simply omitting the AncestorLevel. I thought this would then simply travel towards the root of the visual tree and find the first control with the matching type. I have seen examples on the internet that seem to work this way, and I could have sworn I used this behaviour some years ago. It doesn't work now. Did it ever work or am I just imagining that?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900