views:

113

answers:

1

Hi! I have a question.

I have a WPF UserControl representing a Person with many fields. Some Persons can be a company. In this case I'd like to use another template with other fields. The code behind is the same, that's why I want it as a 1 control only with 2 templates.

What I'd like to do is to be able to define these 2 templates with the VS designer support so I could easily change them.

The problem ist that some elements have EventHandlers attached (Click...) and I can't image how I could resolve that when using DataTemplate. (Perhaps supposing the bubble events register the EventHandler on one of the parents ? and then look for the original source name ?) Or should I use 2 UserControls and then somehow merge them in my main UserControl ?

Thank you in advance

A: 

You could add Commands to your usercontrol class and have the buttons execute the commands. This is a much used pattern in MVVM. See http://codingcontext.wordpress.com/2008/12/10/commandbindings-in-mvvm/ or http://www.codeproject.com/KB/WPF/VMCommanding.aspx

Lars Truijens