blindmeis
blindmeis

Reputation: 22445

Difference between View and Usercontrol when doing MVVM

lately i often see questions regarding MVVM and usercontrol, where - for me - view and usercontrol are mixed up.

for me a View when doing MVVM is just a pretty interface that allows users to interact with my ViewModels - so at least a collection of controls with Bindings. most time xaml only but codebehind not forbidden.

for me a usercontrol instead is not related to a viewmodel at all. the usercontrol has a representation in xaml and of course codebehind where properties, methods and Dependency Properties exist.

i'm on a wrong way with that?

EDIT: of course view and usercontrol inherit from UserControl class - so both technically UserControls. but i use just the term View when doing MVVM. and the term usercontrol just when there is no direct relation to a viewmodel.

ps: my english is too bad to write down what i mean...

Upvotes: 3

Views: 4504

Answers (2)

JSJ
JSJ

Reputation: 5691

A View and User Controls are totally different in MVVM.

The View is a conceptual name of the folder where you put all UI related stuff like user controls, windows, pages, etc. So the View is the folder that contains your GUI part for the particular application.

The User Control is the control which is configured by the developer by mixing multiple components / controls to work like a single control. A user control can also hold the other user controls.

The mix point is that, generally, views hold the user control in an MVVM application, as WPF is XAML based. It gets rendered in there, so the developer can plug your, his and other's user control into some where he wants to.

Whereas windows can not be placed into other windows. And pages can only be shown in frame element, so most views are user controls.

Upvotes: 1

Chen Kinnrot
Chen Kinnrot

Reputation: 21015

You're not wrong just consider the fact the user control can be a reusable view that has a view model. cause the entire composite ui architecture is based on s shell(main window, view) and some regions with view (user controls)

Upvotes: 1

Related Questions