WPF中MVVM的项目结构 [英] Project structure for MVVM in WPF

查看:42
本文介绍了WPF中MVVM的项目结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WPF 中使用 MVVM 时,您最终得到的项目结构是什么?

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

从我现在看到的教程来看,他们通常有文件夹:Model、ViewModel和看法.

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

在模型中,您可以放置​​诸如 Person 之类的类来捕获数据和逻辑.

In Model you put classes like Person for example that capture data and logic.

在 ViewModel 中,您实例化在 Model 中定义的类.视图包含.xaml 文件.

In ViewModel you instantiate classes defined in Model. The View contains .xaml files.

我编辑了我的原始帖子以发送示例项目结构.我有与此相关的问题.我如何组织这些:应用配置应用程序.xaml主窗口.xaml

I edit my original post to send an example project structure. I have question related to this. How do I organize these: App.config App.xaml MainWindow.xaml

我应该像现在一样将它们留在外面还是应该将它们放在某个文件夹中?

Should I leave them outside like they are now or should I put them in some folder?

推荐答案

您已经描述了通常或常见的文件夹布局.根据经验,我更喜欢为模型数据类型添加一个单独的文件夹(或大型应用程序中的项目),例如您提到的典型 Person 类.我这样做的原因是因为这通常会成为最大的项目之一.我也把它拆分成以下子文件夹:

You have described the usual or common folder layout. From experience, I prefer to add a separate folder (or project in large applications) for the model data type, such as the typical Person class that you mentioned. The reason that I do this is because this often becomes one of the biggest projects. I also split it into the following sub folders:

DataTypes
    Collections
    Enums
    Interfaces

我还有单独的文件夹(或大型应用程序中的项目)用于应用程序Converter 类、扩展方法类、实用程序(或服务)类.最后,我有与应用程序文件夹结构非常匹配的测试项目.总的来说,这大致就是我的文件夹的样子:

I also have separate folders (or projects in large applications) for the application Converter classes, extension method classes, utility (or service) classes. Finally, I have test projects that pretty much match the application folder structure. In total, this is roughly what my folders look like:

Solution

    Third Party Libraries <<< (Solution Folder)

    StartUp Project
        Images
        Resources

    Converters

    DataTypes
        Collections
        Enums
        Interfaces <<< (For Data Type classes)

    Extensions

    Models
        Data Controllers
        Data Providers
        Interfaces <<< (For swapping Model classes out in test projects)

    Utilities (Or Services)
        Interfaces <<< (For swapping Utilities classes out in test projects)

    View Models
        Commands

    Views
        Attached Properties
        Controls

更新>>>

项目,就像文件夹一样,只是提供分离级别.他们还帮助我规划我的应用程序命名空间.例如,Collections 文件夹/项目中的代码类将位于 ApplicationName.DataTypes.Collections 命名空间中.Data Providers 文件夹/项目中的类将具有 ApplicationName.Models.DataProviders 命名空间.

Projects, like folders, just provide levels of separation. They also help me to map out my application namespaces. For example, code classes in the Collections folder/project will be in the ApplicationName.DataTypes.Collections namespace. Classes in the Data Providers folder/project will have the ApplicationName.Models.DataProviders namespace.

此外,在大型应用程序中,我的项目名称来自它们在此层次结构中的位置……例如,我的 DataTypes 项目实际上称为 ApplicationName.DataTypes,而我的Models 项目称为 ApplicationName.Models.CollectionsDataProviders 部分是文件夹,以及第二级之后的所有项目,例如.EnumsImagesCommands

Furthermore, in large applications, my project names come from their location in this hierarchy... for example, my DataTypes project is actually called ApplicationName.DataTypes and my Models project is called ApplicationName.Models. The Collections and DataProviders parts are folders, along with all of the items past the second level, eg. Enums, Images, Commands, etc.

这篇关于WPF中MVVM的项目结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆