Should I use the Model-View-ViewModel (MVVM) pattern in Silverlight projects?

前端 未结 12 2005
春和景丽
春和景丽 2020-12-22 17:25

One challenge with Silverlight controls is that when properties are bound to code, they\'re no longer really editable in Blend. For example, if you\'ve got a ListView that\'

相关标签:
12条回答
  • 2020-12-22 18:17

    With the Feb 2009 release of Prism v2 by P&P, even better support for MVVM now available for Silverlight and WPF. See microsoft.com/compositewpf for more details.

    0 讨论(0)
  • 2020-12-22 18:18

    I've always thought MVVM and PresntationModel http://martinfowler.com/eaaDev/PresentationModel.html are essentially the same thing. PresentationModel is a lot easier to say. I've used it succesfully in java swing, windows forms, WPF and silverlight. If you think in terms of separation of concerns a Presentation Model makes a lot of sense. You have one class whose only concern is providing a Presentation friendly Model.It really doesn't matter what technology is used to show it on the screen. It might change some implementation details but splitting the concerns apart is a good idea no matter how you show the information. Because of that separation you can easily write tests against your presentation model regardless of the view technology. So that's a plus.

    0 讨论(0)
  • 2020-12-22 18:20

    I think many of us are waiting for the trailblazers to go ahead and create really good sample apps using MVVM in Silverlight (and WPF for that matter). There are a number of tricky areas such as the lack of ICommand in Silverlight, or the difficulty of interacting with animations starting and stopping only using data binding.

    Its definitely a pattern to watch for the future though, and is worth trying out if you don't mind 'cheating' occasionally in the places where you can't quite figure it out.

    0 讨论(0)
  • 2020-12-22 18:20

    I agree with Jonas. MVVM seems to be the model that works best for me (though John Papa thinks MVP makes more sense). I have an MSDN Article on this coming out in March that hopefully will answer the call for a good example.

    BTW, I would like to see some cohesion in the MVVM Framework department. There isn't a good solution for a framework to follow yet. I like Jonas' (I think Jonas' is the FX Framework) but since its not WPF compatible it might not be the right choice for some.

    0 讨论(0)
  • 2020-12-22 18:22

    There's a very good Techdays 2010 video introduction to the MVVM pattern, clearly explained:

    • TechDays 2010: Understanding the Model-View-ViewModel pattern
    • Hanselminutes podcast by Laurent

    For more complicated applications that require a higher degree of automated testing it definitely makes sense, and the move away from DependencyProperties to DataContext binding is a lot neater than it's ASP.NET counterpart.

    The biggest challenge I've found with Silverlight is testing the actual UI (there's one commercial framework so far I think), and the huge tangle of event calls you get into when using WCF services (or the WebClient for that matter) with Silverlight.

    0 讨论(0)
  • 2020-12-22 18:25

    I've been using MVVM lately on a couple of different Silverlight projects and it's been working really well, I would definitely recommend it. Jonas's post is a great place to start, I've recently blogged on my MVVM experiences too and created a really simple solution to demo the main touch points.

    0 讨论(0)
提交回复
热议问题