Let’s say I want to switCh between 2 UserControls programmatically:
- one UserControl contains a TextBox with a label
- the other contains only TextBox
I’d like a single codebehind. Is it possible ? if yes how ? If not how to do the above requirement ?
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.
If I understand you right, you have two usercontrols acting similar and you don’t want to write the code-behind double?
Create a ViewModel for the controls. Use for both of the controls the same ViewModel. Look at the MVVM-Pattern.
Another possibility would be to create a CustomControl and make two templates.