WPF Best Practices: Do custom controls work well with the MVVM design?

后端 未结 2 1324

I was looking at creating a common control that I will be able to reuse on my pages: an AddressControl which has Address1, Address2, City, State, Zip, etc...

Origina

2条回答
  •  春和景丽
    2020-12-14 03:28

    When using MVVM the Model and ViewModel should not be dependent on the View, that is they should not care what kind of view use them.

    The difference between a custom control and a usercontrol in WPF is that the custom control is lookless and can be customized via its ControlTemplate. This is what you should write if you are writing a generic control library, like Microsoft does. If you however have a specific look in mind for you control, just go with a user control, it is much faster but will only have one look, the one you define for it.

    It is common to use a mix of custom controls and user controls in a MVVM project. For example you would probably use a bunch of custom controls from Microsoft (like textboxes and textblocks) and combine them into user controls.

    See Control Authoring Overview

提交回复
热议问题