开发者

WPF design UserControl / DataTemplate problem

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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜