学习 WPF 和 MVVM - 从头开始​​学习的最佳方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2541484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:37:59  来源:igfitidea点击:

Learning WPF and MVVM - best approach for learning from scratch

wpfmvvm

提问by bplus

I've got about three years c# experience. I'd like to learn some WPF and the MVVM pattern. There are a lot of links to articles on this site but I'm getting a little overwhelmed. Would a sensible approach for a begginer to be forget mvvm for a while and just quickly learn a bit a of WPF, then come back to MVVM?

我有大约三年的 c# 经验。我想学习一些 WPF 和 MVVM 模式。这个网站上有很多文章链接,但我有点不知所措。对于初学者来说,暂时忘记 mvvm 并快速学习一点 WPF,然后再回到 MVVM 是一种明智的方法吗?

I had a leaf through Application=Code+Markup - Charles Petzoldin work today, it doesn't seem to mention MVVM (at least not in the index). I was pretty surprised by this as I thought MVVM was supposed to be the "lingua franca" of WPF?

我在今天的工作中浏览了Application=Code+Markup - Charles Petzold,它似乎没有提到 MVVM(至少在索引中没有)。我对此感到非常惊讶,因为我认为 MVVM 应该是 WPF 的“通用语言”?

Also I've just started working at a new company and they are using MVVM with WinForms, has anyone come across this before?

另外,我刚刚开始在一家新公司工作,他们正在将 MVVM 与 WinForms 一起使用,以前有人遇到过吗?

Can anyone recommend a book that will teach me both WPF and MVVM?

谁能推荐一本教我 WPF 和 MVVM 的书?

回答by Reed Copsey

It depends on your experience.

这取决于你的经验。

I personally felt that this was a lacking area in MVVM discussions, which was what led me to write my series on MVVM and WPF from a Windows Forms developer perspective.

我个人认为这是 MVVM 讨论中的一个缺失领域,这促使我从 Windows Forms 开发人员的角度编写关于MVVM 和 WPF 的系列文章

I would not try to learn WPF without learning MVVM. You'll end up trying to "unlearn" many aspects, as WPF really doesn't make sense, completely, until you understand the separation of presentation and logic that's pervasive throughout the architecture. MVVM is really just extending this same separation into the application space.

我不会在不学习 MVVM 的情况下尝试学习 WPF。您最终将试图“忘记”许多方面,因为 WPF 真的没有任何意义,完全没有意义,直到您了解在整个体系结构中普遍存在的表示和逻辑的分离。MVVM 实际上只是将这种相同的分离扩展到应用程序空间。

As for "MVVM in Windows Forms" - a lot of people try to do this, but it's not really MVVM. In order to do "MVVM" you need access to a richer form of data binding than Windows Forms provides. "MVVM in Windows Forms" is really, typically, just Model-View-Presenter with a different name (riding the MVVM bandwagon, I'd guess), but not really the same as MVVM in WPF.

至于“Windows Forms 中的 MVVM”——很多人尝试这样做,但它并不是真正的 MVVM。为了执行“MVVM”,您需要访问比 Windows 窗体提供的更丰富的数据绑定形式。“Windows 窗体中的 MVVM”实际上通常只是具有不同名称的模型-视图-演示者(我猜是骑着 MVVM 潮流),但与 WPF 中的 MVVM 并不完全相同。

回答by VoidDweller

Jason Dolingerhas an excellent video on the subject. It steps you through the process moving from using code behind files to a full MVVM pattern including Dependency Injection and Testing.

Jason Dolinger有一个关于这个主题的精彩视频。它会引导您完成从使用文件隐藏代码到包括依赖注入和测试在内的完整 MVVM 模式的过程。

Bill Steeledid a 16 part "Soup-to-Nuts" webcast series on WPF. The links on the msevents site are broken. Here is a Google searchto find them. This will help with the WPF learning curve. And he does NOT use any MV* patterns in his examples.

Bill Steele在 WPF 上做了一个 16 部分的“Soup-to-Nuts”网络广播系列。msevents 站点上的链接已损坏。这是一个谷歌搜索来找到它们。这将有助于 WPF 学习曲线。而且他在他的例子中没有使用任何 MV* 模式。

EDIT: The MSEventslinks are working now, I am leaving the Google searchas a backup.

编辑:MSEvents链接现在正在工作,我将谷歌搜索作为备份。

Josh Smithalso has an excellent article WPF Apps With The Model-View-ViewModel Design Patternon MSDN.

Josh Smith在 MSDN 上还有一篇出色的文章WPF Apps With The Model-View-ViewModel Design Pattern

Herding Code: Presentation Patterns with Jeremy Miller, Ward Bell, Rob Eisenberg and Glenn Block

Herding Code:与 Jeremy Miller、Ward Bell、Rob Eisenberg 和 Glenn Block 的演示模式

MIX10:

混合10:

And of course Reed Copsey's MVVM articlesare worth a read as well.

当然,Reed Copsey 的MVVM 文章也值得一读。

回答by LBugnion

I was told a few times that my MIX10 session was explaining the MVVM pattern well enough for beginners (even though some parts are actually quite advanced, so don't worry if you need to re-watch certain parts).

有几次有人告诉我,我的 MIX10 会议对初学者来说已经足够好地解释了 MVVM 模式(尽管有些部分实际上非常先进,所以如果您需要重新观看某些部分,请不要担心)。

The session is at http://live.visitmix.com/MIX10/Sessions/EX14

会议在http://live.visitmix.com/MIX10/Sessions/EX14

Sorry for the self-promotion.

对不起,自我推销。

Cheers, Laurent

干杯,洛朗

回答by Catalin DICU

There aren't many books covering MVVM but there is one : Advanced MVVM

介绍 MVVM 的书籍并不多,但只有一本:Advanced MVVM

But there are lots of online resources and this one is a must read : WPF Apps With The Model-View-ViewModel Design Pattern

但是有很多在线资源,这个是必读的:WPF Apps With The Model-View-ViewModel Design Pattern

After that I suggest looking into frameworks like

在那之后,我建议研究像这样的框架

回答by Shivprasad Ktheitroadala

Here is a tutorial for MVVM http://www.codeproject.com/Articles/819294/Learn-WPF-MVVM-step-by-step-Basics-to-Advance-Levewhich goes from basic to the advance level in 5 steps. So its like graduating from a 3 layer to full MVVM.

这是 MVVM 的教程http://www.codeproject.com/Articles/819294/Learn-WPF-MVVM-step-by-step-Basics-to-Advance-Leve 分5 个步骤从基本到高级. 所以这就像从 3 层毕业到完整的 MVVM。

enter image description here

在此处输入图片说明

回答by Ignacio Soler Garcia

To do big things (like learning WPF + MVVM) it is better to break the task in smaller steps.

要做大事(比如学习 WPF + MVVM),最好以较小的步骤分解任务。

I think that the best approach in this situation is to start by learning the UI part of Wpf. Learn XAML syntax, the layout system, the available controls and forget about binding and how to deliver data to the controls.

我认为在这种情况下最好的方法是从学习 Wpf 的 UI 部分开始。学习 XAML 语法、布局系统、可用控件,忘记绑定以及如何将数据传递到控件。

Once you know the UI basics of Wpf then it is time to move to MVVM. Learn how bindings work and the MVVM pattern.

一旦您了解了 Wpf 的 UI 基础知识,就可以转向 MVVM。了解绑定的工作原理和 MVVM 模式。

In this Web you can find a tutorial focusing on the hands on but with the theory available:

在此 Web 中,您可以找到一个侧重于动手操作但提供可用理论的教程:

http://www.learnmvvm.com

http://www.learnmvvm.com

回答by WPFNovice

Try this site. It collects the various resources at one place. http://learnandmasterwpf.blogspot.com/

试试这个网站。它将各种资源集中在一处。 http://learnandmasterwpf.blogspot.com/

回答by Ashley Davis

I just read this book. It is not really about learning WPF, but it should be useful once you already know a bit of WPF and want to progress your understanding of MVVM.

我刚读完这本书。它并不是真正关于学习 WPF,但是一旦您已经了解了一些 WPF 并希望进一步了解 MVVM,它应该会很有用。

http://www.amazon.co.uk/Pro-WPF-Silverlight-MVVM-Model-View-ViewModel/dp/1430231629

http://www.amazon.co.uk/Pro-WPF-Silverlight-MVVM-Model-View-ViewModel/dp/1430231629