Project structure for MVVM in WPF

后端 未结 4 725
眼角桃花
眼角桃花 2020-12-04 05:35

What is the project structure you end up with when using MVVM in WPF?

From the tutorials I saw now, they usually have folders: Model, ViewModel and View.

In

4条回答
  •  失恋的感觉
    2020-12-04 06:07

    Most people use the "standard" structure you mentioned:

    • Model/
      • CarModel.cs
      • DriverModel.cs
    • ViewModel/
      • CarViewModel.cs
      • DriverViewModel.cs
    • View/
      • CarView.xaml
      • DriverView.xaml

    I think the reason why it's popular is because some people will argue that you should be able to put Models, ViewModels and Views in different assemblies.

    Also with this structure, you can easily add folders for other WPF stuffs: Converters/, Resources/, etc.

    Within my team, we use this structure but we pluralize the names (so Models/ViewModels/Views).

    However, most of the time, model classes are defined in other assemblies/namespace; in that case, we don't even have a Models/ folder.

    For large projects, we add subfolders into the Models/, ViewModels/ and Views/

    For the sake of completeness, it's worth mentioning that you may find a few people using a "feature driven" structure:

    • Car/
      • CarModel.cs
      • CarViewModel.cs
      • CarView.xaml
    • Driver/
      • DriverModel.cs
      • DriverViewModel.cs
      • DriverView.xaml

    But it's very uncommon.

提交回复
热议问题