C# WPF 学习曲线有多糟糕?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1212245/
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-08-06 11:02:41  来源:igfitidea点击:

How bad is the WPF Learning Curve?

c#wpf

提问by SwDevMan81

I've read and heard from several people that WPFhas a pretty steep learning curve (depending on how knowledgeable or experienced you are). Seems like most people can get the demo or starter projects to work, and then find themselves getting stuck for lengths of time on miscellaneous problems. I'm curious what specifically is difficult to learn or understand (layers, SDK, XAML, data binding, etc.) and if you have any suggestions on how to avoid/alleviate some of those difficult topics?

我从几个人那里读到并听说WPF有一个非常陡峭的学习曲线(取决于你的知识或经验)。似乎大多数人可以让演示或入门项目工作,然后发现自己在各种问题上陷入困境。我很好奇什么特别难以学习或理解(层、SDK、XAML、数据绑定等),如果您对如何避免/减轻其中一些难题有任何建议?

采纳答案by Rhys

WPF is different; there is no getting away from that.

WPF 不同;没有办法摆脱这一点。

My main advice is do not be afraid of XAML; Embrace it, that is where the power is!

我的主要建议是不要害怕 XAML;拥抱它,这就是力量所在!

Let me explain:-

让我解释:-

For me to be productive, I prefer to write XAML in the text view as I can create the bare layout of the window in a few keystrokes. If you regularly type code then this is a very quick way to develop windows. You can then use the Visual editors to make it look pretty.

为了提高工作效率,我更喜欢在文本视图中编写 XAML,因为我可以通过几次按键创建窗口的裸露布局。如果您经常键入代码,那么这是开发 Windows 的一种非常快速的方法。然后您可以使用可视化编辑器使其看起来更漂亮。

If you keep in your mind that each element of the XAML will "new" that object and that each attribute of that XAML element is a property of the object, you can think of XAML as object creation and assignments of properties. Very similar to writing code.

如果您牢记 XAML 的每个元素都会“ new”该对象,并且该 XAML 元素的每个属性都是该对象的一个​​属性,那么您可以将 XAML 视为对象创建和属性分配。非常类似于编写代码。

If you spend too much time in the visual designer then you do not get to appreciate this, and for some this will slow down the learning curve.

如果您在视觉设计师身上花费太多时间,那么您就不会意识到这一点,对于某些人来说,这会减慢学习曲线。

A recent Hanselminutespodcast may interest you.

最近的Hanselminutes播客可能会让您感兴趣。

I also advise strongly to learn early the concepts of Views and View-Models, even if you do not subscribe to all that is part of CompositeWPFas this really does help.

我还强烈建议尽早学习视图和视图模型的概念,即使您不订阅CompositeWPF 的所有内容,因为这确实有帮助。

回答by Erich Mirabal

From the few people I worked with that had to learn it, they really recommend going through all the tutorials from Expression Blend. That gave them a good background on WPF and the better tool to use when working with it.

从与我一起工作的少数人必须学习它,他们真的建议您阅读 Expression Blend 的所有教程。这为他们提供了 WPF 的良好背景以及在使用它时使用的更好工具。

回答by BBlake

If you have experience with HTML or XML or similarly based languages, it's not exceptionally difficult, especially if you have web design experience. If you're coming strictly from a WinForms background, the learning curve is a bit steeper. I am currently learning WPF myself and since I come from an extensive web development background, I'm not finding the concepts all that difficult to master for most of them. I've found the online tutorial videos at WindowsClient.net to be exceptionally helpful as well, if a bit poorly organized.

如果您有使用 HTML 或 XML 或类似的语言的经验,这并不是特别困难,特别是如果您有网页设计经验。如果您严格来自 WinForms 背景,学习曲线会更陡峭。我目前自己正在学习 WPF,并且由于我来自广泛的 Web 开发背景,因此我发现其中的大多数概念并不难掌握。我发现 WindowsClient.net 上的在线教程视频也非常有帮助,如果组织得不好的话。

回答by Patrick Desjardins

I have been playing with .NET for more than 4 years, mostly Windows Formsapplications. Binding is not something unknown and I try to use good practice in all my C# applications. For the past 1 month, I have been learning WPF for the job and I have to admit that it's VERY powerful but a lot harder to achieve things. You can do a lot more and achieve some cool designs with less effort but only once you know how it really works and it's hard because it's huge.

我已经使用 .NET 超过 4 年了,主要是Windows 窗体应用程序。绑定并不是什么未知的东西,我尝试在我所有的 C# 应用程序中使用良好的实践。在过去的 1 个月里,我一直在为这份工作学习 WPF,我不得不承认它非常强大,但要实现目标要困难得多。你可以做更多的事情,用更少的努力完成一些很酷的设计,但只有当你知道它是如何真正工作的时候,这很难,因为它很大。

More, debugging is harder - that makes the learning more slow too. The problem I think is the IDE of Visual Studio that doesn't help much in the XAML and you rapidly miss some features of IntelliSenseof C# when doing binding or other stuff that now is in a XML tag. I like it but yes, the learning curve is not smooth.

此外,调试更难——这也让学习变得更慢。我认为的问题是 Visual Studio 的 IDE 在 XAML 中没有多大帮助,并且在进行绑定或现在位于 XML 标记中的其他内容时,您很快就会错过C# IntelliSense的某些功能。我喜欢它,但是是的,学习曲线并不顺利。

回答by Arcturus

There is a nice article from Karsten Januszewski called Hitting the Curve: On WPF and Productivityyou might find interesting:

Karsten Januszewski 有一篇很棒的文章,名为 Hitting the Curve: On WPF and Productivity您可能会发现有趣:

Let's be clear: WPF comes with a curve. I've now watched a bunch of developers hit that curve. And the curve is steep. We're talking between two weeks to two months of curve depending on the developer and the level of experience/intuition the developer has. There will be moments of total mystification and plenty of moments of illumination. It is at once painful and enjoyable, if the developer delights in the discovery of a deep and well thought out UI platform. It is at once familiar and alien. There are many similarities to other UI development paradigms: styles feel like CSS, well sort of. XAML code behind feels like ASP.NET, well sort of. 3D feels like DX or OpenGL, well sort of. Routed events feel like .NET events, well sort of. Dependent properties feel like properties, well sort of. The list could go on. But admidst these (sort of) familiar metaphors there are so many alien concepts that must be mastered: control templating, storyboards, databinding come to mind immediately. It is not a trivial curve and don't expect to be productive on day 1 or even week 1 or even month 1.

让我们明确一点:WPF 带有曲线。我现在已经看到一群开发人员达到了这个曲线。而且曲线很陡。我们讨论的是两周到两个月的曲线,具体取决于开发人员和开发人员的经验/直觉水平。会有完全神秘化的时刻和大量的启迪时刻。如果开发人员对发现一个深思熟虑的 UI 平台感到高兴,那将是既痛苦又令人愉快的。它既熟悉又陌生。与其他 UI 开发范式有许多相似之处:样式感觉就像 CSS 一样。背后的 XAML 代码感觉就像 ASP.NET,有点像。3D 感觉就像 DX 或 OpenGL,差不多。路由事件感觉就像 .NET 事件一样。依赖属性感觉就像属性,好吧。这份名单可以继续使用。但是在这些(有点)熟悉的比喻中,有许多必须掌握的陌生概念:控制模板、故事板、数据绑定立即浮现在脑海中。这不是一条微不足道的曲线,不要指望在第 1 天甚至第 1 周甚至第 1 个月有成效。

It's all worth it though! ;)

不过这一切都是值得的!;)

回答by EightyOne Unite

It's going to be one of those 'it depends' answers but all it reallydepends on is if you're the kind of developer that tries to continually improve your skills. If that's the case then it comes down to a couple of things ultimately.

这将是那些“视情况而定”的答案之一,但真正取决于您是否是那种试图不断提高技能的开发人员。如果是这种情况,那么最终归结为几件事。

Buy WPF Unleashed(others books are available but I whole-heatedly recommend this one), work through the examples and in about 2 months or so you'll wonder how you ever got things done without it.

购买WPF Unleashed(其他书籍也可用,但我强烈推荐这本),完成示例,然后在大约 2 个月左右的时间里,您会想知道如果没有它,您是如何完成工作的。

It's not rocket science and there are no paradigm shifting concepts to deal with. In fact, if you are used to keeping a good separation between your logic and presentation it should fit right in.

这不是火箭科学,也没有要处理的范式转换概念。事实上,如果你习惯于在你的逻辑和表现之间保持良好的分离,它应该适合。

To get to a level of mastery you're probably looking between 6 and 12 months of playing with it.

为了达到精通的水平,您可能需要 6 到 12 个月的时间来玩它。

Good luck.

祝你好运。

回答by bsk

It can be pretty steep.

它可能非常陡峭。

I spent the better part of a month experimenting with WPF and writing a mock-up of our current product in it without developing an intuition for its databinding model or even figuring out how Microsoft means for it to be used. It took me much less time to grasp the basics of ASP.NET MVC.

我花了一个月的大部分时间来试验 WPF 并在其中编写我们当前产品的模型,但没有对其数据绑定模型产生直觉,甚至没有弄清楚 Microsoft 对它的使用意味着什么。我花了更少的时间来掌握 ASP.NET MVC 的基础知识。

[Our application displays/depends on a lot of real time data, and I used the Windows Presentation Foundation book by Nathan. Perhaps another book would have been more appropriate.]

[我们的应用程序显示/依赖于大量实时数据,我使用了 Nathan 的 Windows Presentation Foundation 一书。也许另一本书会更合适。]

回答by Rhys

WPF is easy once you get the general idea of how it works - try "WPF - how and why". The biggest problem is working out if it is worth it at all and there is still a lot of applications that would be fine implemented as Windows Forms plus a bit of graphics.

一旦您对WPF 的工作原理有了大致的了解,WPF 就很容易了 - 尝试“ WPF - 如何以及为什么”。最大的问题是弄清楚它是否值得,仍然有很多应用程序可以很好地实现为 Windows 窗体加上一些图形。

I would also agree with the earlier comment about getting into XAML - it's just like a slightly more sophisticated HTML and the only real difficulty is finding out what does what. As for getting stuck later on in a project - don't you always get stuck later on in a project? It is when you start trying to do the 1% that's tough.

我也同意之前关于进入 XAML 的评论——它就像一个稍微复杂的 HTML,唯一真正的困难是找出什么做了什么。至于后来在项目中陷入困境 - 你不是总是在项目中陷入困境吗?当你开始尝试做那 1% 时,这很困难。

回答by Sergey Aldoukhov

Yes, it is not an easy walk - but be not afraid. The thing about WPF, it is beautifully engineered so you get a constant positive emotional feedback (at least I did ;) when learning it. You like sitting playing with it and exclaim "WOW" every few minutes ;)

是的,这不是一件容易的事情——但不要害怕。关于 WPF,它设计精美,因此在学习它时您会得到持续的积极情绪反馈(至少我做到了;)。你喜欢坐着玩它,每隔几分钟就惊呼“哇”;)

回答by kyoryu

The difficulty with learning WPF is not so much the API as the model. It's a very different mental model than you'd use with something like Windows Forms.

学习 WPF 的困难与其说是 API,不如说是模型。这是一种与您在Windows Forms 之类的东西中使用的思维模型截然不同的思维模型。

Rather than writing methods that imperatively populate a UI element, you generally data bind to properties on an object. To get complex behavior, you generally use some level of composition.

与编写强制填充 U​​I 元素的方法不同,您通常将数据绑定到对象的属性。为了获得复杂的行为,您通常使用某种程度的组合。

As an example, if you have a series of items you want in a list, with a piece of text followed by an image. In Windows Forms, you'd get the list and iterate it. For each item in the list, you'd create the control for the item, and the text, and add the picture, and then add the new subcontrol to the list. (Exact procedure may vary based on the type of control. You may add SubItems instead of just making one control, etc.).

例如,如果您在列表中有一系列想要的项目,其中包含一段文本和一个图像。在 Windows 窗体中,您将获得列表并对其进行迭代。对于列表中的每个项目,您需要为项目创建控件和文本,并添加图片,然后将新的子控件添加到列表中。(具体过程可能因控件类型而异。您可以添加子项而不是只制作一个控件等)。

WPF would handle this very differently. In WPF, at the top level, you'd declare a container object and bind it to the list.

WPF 会以非常不同的方式处理这个问题。在 WPF 中,在顶层,您将声明一个容器对象并将其绑定到列表。

You would then give that container a template to use to display its items. The template is basically another control, which defines the positioning of sub-elements, which are bound off of an instance of the class that the list is populated with.

然后,您将为该容器提供一个模板,用于显示其项目。模板基本上是另一个控件,它定义子元素的定位,这些子元素绑定到列表所填充的类的实例。

It ends up with a very compositional feel, and is absurdly powerful. It's also a very different model than most developers are used to, and until you can internalize the model it's very common to run into problems trying to do things the way that you would in Windows Forms/etc.

它最终呈现出一种非常构图的感觉,并且非常强大。它也是一个与大多数开发人员习惯的非常不同的模型,并且在您可以将模型内部化之前,在尝试以 Windows 窗体/等方式做事时遇到问题是很常见的。

Once you get used to the model, though, going back to other APIs is painful. Not because they're suddenly hard, but because you know how easy things can be.

但是,一旦您习惯了该模型,返回到其他 API 就会很痛苦。不是因为它们突然变得困难,而是因为你知道事情可以变得多么容易。