新 C# WPF MVC 项目的建议
我正在使用WPF 4开发一个系统。我假装在开发中使用MVC。
我以前从未使用过MVC,所以我对概念有点困惑。一段时间(很多年)前,我或多或少地使用该方案开发了一些 Delphi 软件:
- 一个瘦客户端应用程序,安装在与瘦客户端对话的多台机器上,
- ...服务器应用程序与瘦客户端对话,并且是唯一的服务器应用程序。连接到数据库。
在那个新项目中,我假装使用 WPF 开发瘦客户端(MVC 的视图部分),但其他部分我不确定我需要做什么。举例来说: 1.“模型”部分将是我的服务器应用程序,但“控制器”将在客户端或服务器计算机上工作?
2. 这种情况下,服务器和客户端之间如何进行通信?插座?远程处理?
3.你推荐什么?有一些“Basic Sample”之类的项目可以下载和学习吗?
我在这里谢谢你的光:)
I'm developing a system using WPF 4. I pretend to use MVC in development.
I never used MVC before, so I'm a little confused about concepts. Some time (ages) ago I develop some Delphi software more or less with that scheme:
- a thin client application to be installed in several machines that talk with the...
- ...server application that talks with the thin clients and is the only that connects to database.
In that new project, I pretend develop that thin client (the View part of MVC) using WPF, but the another pieces I'm unsure what I need do. By example:
1. The "Model" part will be my Server application, but the "Controller" will work on the client or server machine?
2. How I do the communication between server and client in that case? sockets? remoting?
3. What you recommend? There is some "Basic Sample" that kind of project to download and to study?
I thank you any light here :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MVVM(模型视图视图模型)是一种类似 MVC 的设计模式,非常适合 WPF 和 Silverlight 开发,部分原因是它专注于绑定,而 Xaml 在绑定方面具有很强的功能。
对于客户端-服务器通信,WCF 服务是目前推荐的方法。
有很多关于 MVVM 客户端、基于 WCF 通信的应用程序的介绍性文章。这是我从自己那里学到的一个示例:
http://calcium.codeplex.com/
此外,还有有许多可用于 WPF 的 MVVM 框架。其中包括:
MVVM Light(简单且易于上手):
http://www.galasoft .ch/mvvm/getstarted/
Caliburn(功能强大且功能丰富):
http://caliburn.codeplex .com/
MVVM (Model View View Model) is a MVC-like design patern that is very well suited to WPF and Silverlight development, in part because of its focus on binding, at which Xaml is highly functional.
As for client-server communication, WCF services is the recommended approach these days.
There are many introductory articles out there on MVVM client, WCF communication based applications. Here's one sample that I learned off of myself:
http://calcium.codeplex.com/
Additionally, there are many MVVM frameworks out there available for WPF. A couple are:
MVVM Light (simple and easy to get started with):
http://www.galasoft.ch/mvvm/getstarted/
Caliburn (highly functional and feature rich):
http://caliburn.codeplex.com/
+1 给 jeffn,因为 WPF 中的 MVC 模式称为 MVVM。它是该模式的一种变体,与 WPF 的绑定基础结构很好地混合在一起。
您的“客户端”应用程序将包含模型、视图和视图模型(模型、视图和控制器)。您不会尝试跨服务器/客户端边界分割模式。它不实用,而且不会为你节省任何东西。如果客户端和服务器之间有任何代码共享,那就是模型。
下面是一个场景:
用户单击请求用户列表的按钮。该按钮绑定到 ViewModel 上 ICommand 类型的属性。单击按钮会触发 ICommand 的 Execute 方法,ViewModel 将其解释为对用户的请求。
ViewModel 通过 WCF 服务连接到服务器。服务器将所有用户收集到 User 类型的实例中,并通过网络将它们发送回。
然后,ViewModel 获取这些反序列化的 User 实例并将它们放入 ObservableCollection 中。该集合绑定到 UI 中的 ListControl。
+1 to jeffn, as the MVC pattern in WPF is called MVVM. It is a variation on the pattern that mixes very well with the binding infrastructure of WPF.
Your "client" app would contain models, views and viewmodels (models, views, and controllers). You wouldn't try to split the pattern across the server/client boundary. It isn't practical and saves you nothing. If there is any code sharing between the client and the server it would be the Models.
Here's a scenario:
User clicks on a button requesting a list of users. The button is bound to a property of type ICommand on the ViewModel. The button click fires the Execute method of ICommand, which the ViewModel interprets as a request for users.
The ViewModel connects to the server via a WCF service. The server gathers all users into instances of type User and sends these back across the wire.
The ViewModel then takes these deserialized User instances and places them in an ObservableCollection. This collection is bound to a ListControl in the UI.