In my experience, the development path tends to work this way:
Design a view in Blend or Kaxaml or whatever, and a view model that backs the view.
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.
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.
发布评论
评论(1)
根据我的经验,开发路径往往是这样的:
有时我会提前知道我需要使用方法#3,并且我从一开始就针对它进行设计。
但 WPF 和 MVVM 的优点之一是,即使我没有从一开始就为此进行设计,如果情况需要,朝着这个方向前进也不会太难。一旦您完成了几次,将一堆视图模型属性重构为单个视图模型集合就不会花费大量时间或精力。
不过,我可以告诉您:制作 XAML 对象的副本并对其进行编辑会让我的脑海中响起喇叭声。可以想象在什么情况下这种情况可能没问题,但这不是下注的方式。
In my experience, the development path tends to work this way:
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.