开发者

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

Let's say I want to switCh between 2 UserControls progr开发者_如何学Goammatically:

  • 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.


Why not have one usercontrol and switch the Visibility of the Label using a style trigger based on some property of the datacontext?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜