WPF - Should a user control have its own ViewModel?

后端 未结 5 1007
梦毁少年i
梦毁少年i 2020-11-27 14:32

I have a window made up of several user controls and was wondering whether each user control have its own ViewModel or should the window as a whole have only one ViewModel?<

5条回答
  •  醉酒成梦
    2020-11-27 14:49

    I guess your application is doing some sort of view composition, so if you make your user controls to have its own view model, you'll have more freedom to embed them in other host windows without changing the window global view model.

    As an added bonus, your application will be more suited to evolve to a more architecturally-sound composition model as that provided by Prism or Caliburn frameworks, if the application requirements arise.

提交回复
热议问题