Can someone explain me the following XAML line?
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Here the simple example of use.
How to replace that line with a C# code?
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.
That simply sets the
DataContextproperty equal to the object with the property. The code equivalent would bethis.DataContext = this;Edit
The
DataContextproperty is the object that is used as the context for all the bindings that occur on this object and its child objects. If you don’t have aDataContextcorrectly set to the model you want to bind to, all of your bindings will fail.Edit2
Here is how to set it in code behind (matching your example):