使用 MVVM 组合 XAML(Silverlight 和 WPF)复杂 UI

发布于 2024-12-06 01:09:16 字数 1431 浏览 1 评论 0原文

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

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

发布评论

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

评论(1

友欢 2024-12-13 01:09:16

根据我的经验,开发路径往往是这样的:

  1. 在 Blend 或 Kaxaml 等中设计一个视图,以及支持该视图的视图模型。
  2. 意识到视图的某些部分需要是动态的。在视图模型中实现标志并在视图中实现样式以显示/隐藏它们。
  3. 意识到所有的旗帜都失去了控制。摆脱标志,并重构视图以呈现用户控件的集合,并重构视图模型以动态填充视图模型的集合。

有时我会提前知道我需要使用方法#3,并且我从一开始就针对它进行设计。

但 WPF 和 MVVM 的优点之一是,即使我没有从一开始就为此进行设计,如果情况需要,朝着这个方向前进也不会太难。一旦您完成了几次,将一堆视图模型属性重构为单个视图模型集合就不会花费大量时间或精力。

不过,我可以告诉您:制作 XAML 对象的副本并对其进行编辑会让我的脑海中响起喇叭声。可以想象在什么情况下这种情况可能没问题,但这不是下注的方式。

In my experience, the development path tends to work this way:

  1. Design a view in Blend or Kaxaml or whatever, and a view model that backs the view.
  2. Realize that portions of the view need to be dynamic. Implement flags in the view model and styles in the view to show/hide them.
  3. Realize that all the flags are getting out of hand. Get rid of the flags, and refactor the view to present collections of user controls, and the view model to dynamically populate collections of view models.

It sometimes happens that I know well in advance that I'm going to need to use approach #3, and I design for it from the start.

But one of the beauties of WPF and MVVM is that even if I don't design for this from the start, it's not too hard to move in that direction if circumstances demand it. Refactoring a bunch of view model properties into a single collection of view models doesn't take a whole lot of time or effort once you've done it a few times.

I can tell you this, though: making a copy of a XAML object and editing it makes klaxons sound in my head. It's possible to imagine circumstances under which that might be OK, but it's not the way to bet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文