开发者

WPF Listview Manipulation

Recently, I asked this question.

The responses to this, and pretty much every other article that I found about this subject basically said to always bind the l开发者_StackOverflow社区ist view to a data source and manipulate that instead. What I can't find is anywhere that says why?


Because it can be easier and cleaner to seperate domain from presentation.

Winform apps were event-driven. You had to handle various control events and write events in the code-behind. So the programmer was in charge of initializing the controls/widgets, handling changes as well as writing back changes to the underlying store. This can lead (and usually does) to lots of logic getting embedded into the GUI. As a result, it is difficult to test the app without going via the GUI.

WPF has changed this quite a bit. WPF's databinding support ensures that your UI updates and is in-sync with the domain objects it is presenting. So you can modify the underlying collection by doing an Add() and the bound UI would pick up this change and update itself. So the wiring between the UI and the underlying datasource/store is now handled declaratively (no code needs to be written). You can now focus completely on the underlying domain objects. Also it is quite pleasant to write automated tests against.

IMHO you tend to be much more productive and produce cleaner designs, once you get the hang of it. Check out Josh Smith's msdn article on MVVM with WPF

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜