在WPF项目结构MVVM [英] Project structure for MVVM in WPF
问题描述
什么是你最终的项目结构中使用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屋!