How can I dynamically & ldquo; link & rdquo; one class to another xaml?

advertisements

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 ?


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.