使用MVC设计模式编写点网桌面应用程序

发布于 2024-10-10 08:59:44 字数 161 浏览 7 评论 0原文

我接到一项任务,要求使用 C# 制作桌面应用程序。它必须使用 MVC 设计模式来完成,但我找不到任何可以展示如何使用基于桌面的应用程序来完成此操作的教程。我能找到的所有教程都展示了如何在网络(asp.net)上执行此操作。

所以我想知道是否有人可以向我推荐一本正在执行此操作的书籍或在线教程?

I got an assignment to make a Desktop application using C#. It has to be done using MVC design pattern, but I can't find any tutorial which can show how to do it with Desktop based application. All the tutorials which I can find show how to do it for web (asp.net).

So I was wondering if someone can suggest me a book or online tutorial which is doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

罗罗贝儿 2024-10-17 08:59:44

我总是通过这样做来学习这是一个非常基本的例子。 Web或Windows,没关系...

Model

// basic template for what your view will do
public interface IProgram
{
    public string FirstName { get; set; }
}

View

public class Program : IProgram
{
    ProgramController _controller;
    public Program()
    {
        // pass itself to the controller
        _controller = new ProgramController(this);
    }

    public string FirstName 
    {
        get { return firstNameTextBox.Value; }
        set { firstNameTextBox.Value = value; }
    }
}

Controller

public class ProgramController
{
    IProgramView _view;
    public ProgramController(IProgramView view)
    {
        // now the controller has access to _view.FirstName
        // to push data to and get data from
        _view = view;
    }
}

你可以通过这种方式绑定任何成员,例如事件

I always learned by doing so here's a very basic example. Web or Windows, doesn't matter...

Model

// basic template for what your view will do
public interface IProgram
{
    public string FirstName { get; set; }
}

View

public class Program : IProgram
{
    ProgramController _controller;
    public Program()
    {
        // pass itself to the controller
        _controller = new ProgramController(this);
    }

    public string FirstName 
    {
        get { return firstNameTextBox.Value; }
        set { firstNameTextBox.Value = value; }
    }
}

Controller

public class ProgramController
{
    IProgramView _view;
    public ProgramController(IProgramView view)
    {
        // now the controller has access to _view.FirstName
        // to push data to and get data from
        _view = view;
    }
}

You can bind any members this way, such as events

故笙诉离歌 2024-10-17 08:59:44

由于这是作业,我相信您的老师,更重要的是您自己,都渴望学习 MVC 背后的技巧。因此,虽然检查 MVC 框架可能会有所帮助,但我建议您自己实现基本功能。

也就是说,请查看维基百科的文章 首先(不幸的是,这不是那么好),然后检查 Microsoft 的做法< /a> 就可以了。

一旦掌握了这些概念,就可以尝试实现一个基本的三元组来执行“某事”,但没什么特别的。如果您有疑问,请回到SO,以便我们可以解决。并且不要忘记 SO 的新聊天功能

Since this is homework, I believe that you teacher and, more importantly, yourself, desire to learn the tricks behind MVC. So, while checking MVC Frameworks might help, I recommend you implement basic functionality on your own.

That said, take a look at Wikipedia's article first (which, unfortunately isn't that good), then check Microsoft's take on it.

Once you grasp the concepts, try implement a basic triplet that does "something", nothing really fancy. If you have doubts, come back to SO so that we can solve then. And don't forget the new chat functionality of SO.

情话难免假 2024-10-17 08:59:44

您可能会考虑几种不同的途径。

  • 您可以考虑自己实现该模式。为了从头开始实现该模式,您确实需要了解 MVC 试图解决的问题。
    • 考虑阅读有关设计模式的内容。我知道Head First设计模式包括MVC 模式简介。
    • 您可以考虑探索 ASP.NET MVC。尽管它适用于 Web 而不是桌面,但了解 ASP.NET MVC 通过使用 MVC 模式解决什么问题将帮助您了解如何最好地实现桌面解决方案。
  • 看看是否有人用 WinForms 实现了 MVC
  • 您还可以考虑寻找有关使用 WPF 或 Silverlight 实现 MVC 模式的建议。
    • 尽管围绕 WPF 和 Silverlight 的常见流行语模式是 MVVM(模型-视图-视图模型),但有些人仍然更喜欢使用这些技术的 MVC 实现。
    • 事实上,如果您有意识地创建视图模型来伴随您的视图,即使在使用 MVC 模式时,您本质上也有一个“MV-VM-C”模式,可以确保您的视图只了解属于该模型的数据到那个特定的视图。

There are a few different avenues you might look at.

  • You might consider implementing the pattern yourself. In order to implement the pattern from scratch, you really would need to understand what MVC is trying to solve.
    • Consider reading about Design Patterns. I know that Head First Design Patterns includes an introduction to the MVC pattern.
    • You may consider exploring ASP.NET MVC. Even though it is for the web and not the desktop, understanding what problems ASP.NET MVC is solving by using the MVC pattern will help you to understand how to best implement a solution for the desktop.
  • See if anyone has implemented MVC with WinForms
  • You also might consider looking for suggestions on implementing the MVC Pattern with WPF or Silverlight.
    • Although the common buzzword pattern surrounding WPF and Silverlight is MVVM (Model-View-ViewModel), some people still prefer to use an MVC implementation with these technologies.
    • In fact, if you consciously create View Models to accompany your views even when using the MVC pattern, you've essentially an "M-V-VM-C" pattern that ensures that your views only know about data from the model that pertains to that particular view.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文