Reputation: 38190
Let's say I want to switCh between 2 UserControls programmatically:
I'd like a single codebehind. Is it possible ? if yes how ? If not how to do the above requirement ?
Upvotes: 1
Views: 62
Reputation: 408
Why not have one usercontrol and switch the Visibility of the Label using a style trigger based on some property of the datacontext?
Upvotes: 1
Reputation: 36775
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.
Upvotes: 5