ViewModel 模式最大的痛点是什么?

发布于 2024-07-18 14:14:10 字数 457 浏览 6 评论 0原文

Glenn Block 和我一直在共同研究 ViewModel 模式。 我们一直在努力找出与该模式相关的最大痛点,目标是添加框架支持以减轻痛点。

今晚,格伦发布了,“查看模型”——电影,投下你的一票。 我们希望听到您的意见。 请在此处发布(并投票)关于实现 ViewModel 模式(也称为模型-视图-ViewModel 或 MVVM)的最大痛点。 告诉我们该框架如何让您的生活更轻松!

我们正在研究 WPF 和 Silverlight。

那么请告诉我们,您希望框架做什么来使 ViewModel 变得更容易?

Glenn Block and I have been working together on the ViewModel pattern. We’ve been trying to identify the biggest pain points associated with the pattern, with the goal of adding framework support to alleviate the pain.

Tonight, Glenn posted, “View Model” – the movie, cast your vote. We want to hear from you. Please post here (and vote) on what the biggest pain points are with implementing the ViewModel pattern (also known as Model-View-ViewModel or MVVM). Tell us how the framework can make you life easier!

We are looking at both WPF and Silverlight.

So tell us, what do you want the framework to do to make ViewModel easier?

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

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

发布评论

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

评论(4

眉目亦如画i 2024-07-25 14:14:10
  • 对象爆炸(现在我们拥有模型和视图模型)。
  • 将模型映射到视图模型,反之亦然。

我认为两者都是必要之恶,但却是痛点。

  • Object explosion (Now we have both the model and a view model).
  • Mapping the model to the viewmodel and vice versa.

I think both are neccesary evils, but they are pain points.

简单 2024-07-25 14:14:10

集合。

我希望我的模型具有其他模型对象的集合,但将我的 GUI 绑定到 ViewModel 对象的集合。

我可以在 ViewModel 层中创建一个 ObservableCollection,并为模型级集合中的每个项目手动填充一个 ViewModel。 当程序启动时,效果很好。 但是当用户单击“添加”按钮时会发生什么? 还是删除按钮? 或者上移/下移? 等等。

是的,我可以编写代码来保持 ViewModel 列表与 Model 列表同步,但是有很多微妙的边缘情况,并且需要大量工作(和大量测试)才能正确获取所有细节。 这是一个常见的场景,应该纳入框架中。 (请?)

Collections.

I want my Model to have a collection of other Model objects, but bind my GUI to a collection of ViewModel objects.

I can create an ObservableCollection<TViewModel> in my ViewModel layer, and manually populate that with a ViewModel for each item in the Model-level collection. That works fine -- when the program starts up. But then what happens when the user clicks the Add button? Or the Delete button? Or Move Up / Move Down? Etc.

Yes, I can write code to keep the ViewModel list in sync with the Model list, but there are a lot of subtle edge cases, and it's a lot of work (and a lot of tests) to get all the details right. This is a common scenario and should be baked into the framework. (Please?)

獨角戲 2024-07-25 14:14:10

INotifyCollectionChanged 支持有关更改范围的通知,但当您尝试发布范围更新时,所有 WPF 集合控件都会抛出范围不支持的异常。
这意味着,如果向容器添加 10 个项目,布局将重新计算 10 次,这对于复杂的控件来说相当慢!

解决方案是将 SuspendNotifocations 和 ResumeNotifications 方法添加到 Observable 集合,并使所有 WPF 控件了解范围更新(用例:挂起、添加项目、恢复、立即绘制所有项目)。

INotifyCollectionChanged supports notification about range of changes, but all WPF collection controls throw range not supported exception when you try to post range update.
This means that if you add 10 items to container, the layout is re-evaluated 10 times, which is pretty slow with complex controls!

Solution would be to add SuspendNotifocations and ResumeNotifications methods to Observable collection, and to make all WPF controls aware of range updates (use case: suspend, add items, resume, all items are drawn at once).

ゞ花落谁相伴 2024-07-25 14:14:10

在 ViewModel 类中创建的属性太多。 至少我所看到的,对于您想要访问/绑定的 UI 元素的每个属性,您需要在 ViewModel 中创建属性,这需要维护太多代码。

Too many properties to create in ViewModel class. At least what I have saw, for each property of UI element you want to access/bind you need to create property in ViewModel that is too much code to maintain.

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