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

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

问题描述

什么是你最终的项目结构中使用WPF MVVM时?

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, ModelView and View.

在型号你把类,如人的例子,捕获数据
和逻辑。

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

在模型视图您实例化模型中定义的类。该视图包含
的.xaml文件。

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

编辑:编辑我原来的职位发送一个示例项目结构。
我有关于这个问题。我如何组织这些:
App.config中
App.xaml中
MainWindow.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?

推荐答案

您所描述的一般或通用文件夹的布局。从以往的经验,我preFER添加一个单独的文件夹(或大型应用程序项目)为模型的数据类型,比如你提到的典型类。我这样做的原因是因为这往往成为最大的项目之一。我还它拆分成以下子文件夹:

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

我也有应用程序转换类,扩展方法类,实用程序(或服务)类单独的文件夹(或在大型应用项目)。最后,我有测试项目,这些项目pretty多少匹配的应用程序文件夹结构。总体而言,这大致就是我的文件夹如下:

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

更新>>>

项目,如文件夹,只需提供分离的水平。他们还帮助我描绘出我的应用程序的命名空间。例如,在集合code类文件夹/项目将在 ApplicationName.DataTypes.Collections 命名空间。在数据提供程序类文件夹/项目将有 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.

此外,在大型应用程序,我的项目名称来源于他们的位置在这个层次...例如,我的数据类型项目实际上是所谓的 ApplicationName.DataTypes 我的模式项目被称为 ApplicationName.Models 。在收藏的dataProvider 部分文件夹,所有的项目过去的第二个层次,如沿。 枚举图片命令

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天全站免登陆