新手对PRISM和MVVM的看法... [英] Thoughts on PRISM and MVVM from a newbie...

查看:89
本文介绍了新手对PRISM和MVVM的看法...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

曾经致力于理解MVVM,当然还涉及PRISM.认为棱镜将全部解决".对我来说,我很快发现它变得非常真实.从棱镜的外观来看,反正我大约需要3个月到6个月的时间 起来.但是我确实喜欢我所看到的...它只是试图使这一切变得新鲜.当我深入研究时,我发现调查UNITY确实是一个很好的方法,可以让人们更多地了解所有这些特殊"知识.必须要做的事情 例如注册资料".实际上,稍后在再次阅读有关Dependency属性的内容时,我发现WPF使用了相同的思想....

但是,当试图让PRISM加载我的内容控件并做一些简单的事情(例如基于按钮单击来换出内容)时,我发现在弄黑它的那一周无法弄清楚.因此,我因此推迟了Prism. 有任何有关棱镜的书吗?

回到MVVM.一切并没有丢失,因为依赖于注入的概念已经成熟了进入Prism,并且MVVM模型中关注点的分离是相似的.都是以松耦合的名义,我很快发现了为什么 命令模式在View中扮演重要角色.主要原因是,如果未为按钮"单击实现命令模式,则视图中的代码将成为执行操作的最合逻辑的位置.但这会造成一点 问题在于所有活动都必须交付给ViewModel.没什么大不了的,但肯定是紧密耦合的.视图将创建视图模型,因此应保持对其的引用.

通过阅读不同的文章,我发现一种评估您的VM模式的方法是如果视图中的控件没有名称,您就接近了".因此,我从这个概念开始,该概念用于最大程度地利用WPF绑定, 这种情况下应归于ViewModel.当我开始重构代码时,我意识到它是如此紧密地耦合在一起.在我的情况下,MODEL或(数据访问层)实际上是在更新View本身.但是问题是这样,除了用于通过 将Mock对象连接起来,是否真的可以通过将MODEL和VIEWMODEL耦合减少到对父对象真正不了解的程度来真正获得这么多的优势?在这种情况下,更改MODEL以更新VIEWMODEL属性并不难, 但是.....它需要引用在第一次初始化模型本身时存储的VIEWMODEL,即闭合耦合.除了事件,我看不到其他方式可以做到这一点...有评论吗?

肯定是我进入MVVM的途中,但有一定的基础...... APress是否有关于MVVM的良好参考资料?

 

 

 


Javaman

解决方案

就MVVM部分而言,由于视图模型需要是视图的数据上下文,因此视图需要引用视图模型实例.这是一种紧密耦合,单个视图连接到特定类型的视图你不能做的模型 绑定到所有视图的通用视图模型.

请在mvvm上查看josh smith的此链接.

http://joshsmithonwpf.wordpress.com/advanced-mvvm/

第二,对于使用棱镜,您提到的它的基本用途是帮助创建无需大量修改即可用于wpf和silverlight的应用程序.

请查看这些链接,以结合使用棱镜和mvvm.这些文件也包含文档和示例代码.

我认为您可以首先使用PRISM编写一个简单的应用程序.

http://compositewpf.codeplex.com/

http://elegantcode.com/2009/06/05/bsdg-prismmvvm-for-wpf-presentation-sample-code/

 


Been working on trying to understand MVVM and of course ran across PRISM.  Thinking that Prism would "set it all up" for me, I quickly found it gets real deep real quick.  From the looks of Prism, to me anyway, it's about a 3 month to 6 month ramp up.  But I did like what I saw... it was just trying to get to the newness of it all..  As I dug in deeper, I found that looking into UNITY is really a good way for one to learn a bit more about all of these "Special" things that have to be done like "Registering stuff".  In fact, later when reading up again for the umpteenth time on Dependancy properties, I find that WPF uses the same ideas.... Ok cool, I guess I'm on to something.

But while trying to get PRISM to load my content controls and do simple stuff like swapping out content based on a button click, I found it impossible to figure out in the week I hacked at it.  So with that I am holding off on Prism as a result.  Are there any Books on Prism? 

So back to MVVM.  All was not lost because the foray into Prism is ripe with the concept of Dependency injection, and the separation of concerns in the MVVM model is similar.  All in the name of loose coupling, I quickly found out why the Command pattern becomes a big player in the View.  The main reason is that if a command pattern is not implemented for Button clicks, then the code behind in the view becomes the most logical place to perform action.  But this creates a bit of a problem in that all activity has to be shipped off to the ViewModel.  Not a big deal, but definitely close coupled.  The view creates the viewmodel, so maintain a reference to it should be ok.

Through reading differnet posts I found that one way to value your VM pattern is this "if your controls in the view don't have names, you're getting close".  So I started in with this concept which is used to take maximum advantage of WPF binding, in this case to the ViewModel.  As I began to refactor my code I realized how tightly coupled it was.  The MODEL or the (Data Access Layer) was actually in my case updating the View itself.  But the question is this, except for Testing via hooking up Mock objects, do we really gain that much advantage by reducing the MODEL and the VIEWMODEL coupling to the point it really doesn't know about their parentsl?  In this case it wasn't hard to change the MODEL to update a VIEWMODEL property, but..... it required a reference to the VIEWMODEL stored upon the first initialization of the MODEL itself, and that is Close Coupling.  Apart from events I see no other way to do this...  Comments?

Definitely on my way to MVVM but have some ground to cover.... Are there any good reference materials on MVVM from APress?

 

 

 


Javaman

解决方案

Hi,

As far as the MVVM part is concerned, as view model needs to be the data context of view so view needs the reference to viewmodel instance it is kind of close coupling that a single view is connected to a specific type of view model you cant just make a generic viewmodel that is bound to all views.

Please check out this link of josh smith on mvvm.

http://joshsmithonwpf.wordpress.com/advanced-mvvm/

Secondly, for using prism, its basic use as you mentioned is to help create application that is used in both wpf and silverlight without much modifications.

Please check out these links for using prism and mvvm in conjunction. These have documentation and sample code as well.

i think you could start first by making a simple application using PRISM.

http://compositewpf.codeplex.com/

http://elegantcode.com/2009/06/05/bsdg-prismmvvm-for-wpf-presentation-sample-code/

 


这篇关于新手对PRISM和MVVM的看法...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆