user310291
user310291

Reputation: 38190

How can I dynamically "bind" a class to a different xaml?

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

Answers (2)

Dave Lowther
Dave Lowther

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

HCL
HCL

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

Related Questions