I tried this:
Binding binding = new Binding("Content.DataContext");
BindingOperations.SetBinding(tab, DataContextProperty, binding);
It isn’t working. I don’t know why.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You haven’t specified a source for the binding. It is therefore using the local DataContext of the
tabelement. Since thetabelement doesn’t yet have a DataContext (it’s what you’re trying to set), let alone one for which the pathContent.DataContextis meaningful, this isn’t going to work.Instead use something like:
(Depending on your exact requirement you might also want to investigate using Binding.Source instead of Binding.RelativeSource.)
The RelativeSource setting specifies that the binding is to the same element as the binding target rather than to the local DataContext — thus, the DataContext of the control is now bound to the DataContext of the Content of that same control, as required.