How can i set the control.Template from code if my template is placed in an ResourceDictionary?
Share
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.
Fundementally you need to attach to the control’s loaded event. At this point you can assign to the Template property. You can retrieve the template from a resource dictionary.
For example lets assume you have a UserControl that contains a TextBox that you want to provide a different template for in the UserControl’s code and that the template is stored in the UserControls Resources property.
In the code-behind of the UserControl you would have this code:-
In this case I’m using the text box’s own loaded event, however, you can also use the UserControls loaded event.