locked
WPF and MVVM with Prism 4 RRS feed

  • Question

  • Dear all,

    I have basic knowledge of MVVM and start to implement it in some application in redesign spirit. Actually I have donwload Prism 4 and explore the step by step but still some part are straight to unclear when dig example and sample.

    Do you guys, are using prism ?

    Based n your experience what was your learning curve time to implement prism in your application (let say quite simple app) ?

    How do you approach your learning in an efficiant way ? are you doing laps or study given sample from start to begining or do your start to implement right away in your apps ?

    From my case I hate folowing given sample and study them but prefer to work directly on my apps but may be I am wrong.

    In opposite to Prism I have also check a bit the MVVM Light tool kit but unfortunalty for it there is no step by step from start to end learning, or I miss it ?

     

    Thnaks for advise on best learning approach

    regards

    serge


    Your knowledge is enhanced by that of others.
    Friday, November 4, 2011 1:58 PM

Answers

  • To be honest, most MVVM frameworks really don't have documentation. You are forces to either find it out yourself or google it in the hope that someone blogged about it earlier. If you want, you might want to take a look at Catel (see http://catel.codeplex.com), it has decent documentation, and lots of examples and quickstart guides. For example, see this quickstart guide:

    http://catel.catenalogic.com/index.html?creating_your_first_wpf_projec.htm

    You can also find examples here:

    http://catelexamples.codeplex.com

    Lots of people that start with MVVM light finally end up using Catel for the following reasons:

    • Too simple (how to show (non)modal windows
    • How to add logging
    • How about support
    • How about authentication and security
    • How about freedom of the IoC container
    • etc...

    For a full comparison sheet, check this link and decide for yourself what framework to use:

    http://catel.catenalogic.com/index.html?mvvm_framework_comparison_shee.htm


    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a free open-source MVVM framework for WPF, Silverlight and Windows Phone 7? Check out Catel!
    • Marked as answer by Sheldon _Xiao Wednesday, November 16, 2011 9:34 AM
    Friday, November 4, 2011 4:55 PM
  • There are various ways of handling the mapping from ViewModel->View.  The approach I was taking here is a ViewModel first style of MVVM.  This tends to be a bit nicer from a developer's standpoint, though less "designer friendly", especially with blend.

     

    If you look at the same project (you can download it on the last page), you'll see how it's setup.  Basically, the above works great if you want to have nested views inside of a View, and the nested views may be different types.  It allows you to have a single "parent' ViewModel with a View, and then the parent can just set the "content" by setting a property on itself (which can just be defined as Object), and the data template will cause any bound content presenter to map up automatically...

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Sheldon _Xiao Wednesday, November 16, 2011 9:34 AM
    Friday, November 4, 2011 5:34 PM

All replies

  • Hi Serge,

    I'm using Prism at the moment.

    There's a lot to learn, and I would recommend getting to grips with MVVM first.

    One thing at a time.

     

    The MVVM light toolkit is good and it's pretty easy to pick up.

    I started on MVVM light by watching a video by Laurent Bugnion from Mix11.

    I suggest you watch his video from Mix10 about MVVM first and then his "deep dive" from mix11 about mvvm where he shows some examples using the mvvm light toolkit.

    I think once you watch them, you'll probably be OK.

     

    Good luck.

    • Proposed as answer by Sheldon _Xiao Wednesday, November 16, 2011 9:34 AM
    Friday, November 4, 2011 2:45 PM
  • MVVM toolkit hides most of things happening behind the scene and usually before getting to forget hidden things, I was thinking that it is alwys good to know what is happening.

    So in otherwords if I need to strqt to convert a simple applmication to MVVM, should I implement it from scratch and then after going to Light toolkit ?

    Any good steps by tsep turotial from begining to end in order to implement MVVM to a wpf apps ? 

    can you point me to those videos and deep dive ? could not find them or mess up with other stuff

    thnaks

    serge


    Your knowledge is enhanced by that of others.
    Friday, November 4, 2011 2:58 PM
  • Any good steps by tsep turotial from begining to end in order to implement MVVM to a wpf apps ? 

    can you point me to those videos and deep dive ? could not find them or mess up with other stuff

     

    I wrote one that's pretty decent if you're starting with a Windows Forms or similar background.  It's available at: http://reedcopsey.com/series/windows-forms-to-mvvm/

     

    It really just shows the basics of MVVM, so you can get an idea of what it does (and doesn't do) and why it's useful.

     

    Prism or MVVM Light or any other framework would be a smaller learning step up once you understood that portion of the design...

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, November 4, 2011 4:26 PM
  • To be honest, most MVVM frameworks really don't have documentation. You are forces to either find it out yourself or google it in the hope that someone blogged about it earlier. If you want, you might want to take a look at Catel (see http://catel.codeplex.com), it has decent documentation, and lots of examples and quickstart guides. For example, see this quickstart guide:

    http://catel.catenalogic.com/index.html?creating_your_first_wpf_projec.htm

    You can also find examples here:

    http://catelexamples.codeplex.com

    Lots of people that start with MVVM light finally end up using Catel for the following reasons:

    • Too simple (how to show (non)modal windows
    • How to add logging
    • How about support
    • How about authentication and security
    • How about freedom of the IoC container
    • etc...

    For a full comparison sheet, check this link and decide for yourself what framework to use:

    http://catel.catenalogic.com/index.html?mvvm_framework_comparison_shee.htm


    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a free open-source MVVM framework for WPF, Silverlight and Windows Phone 7? Check out Catel!
    • Marked as answer by Sheldon _Xiao Wednesday, November 16, 2011 9:34 AM
    Friday, November 4, 2011 4:55 PM
  • Hello Reed,

    I have checked you blog but could you show how you set teh datacontext when you are using :

    <DataTemplate DataType="{x:Type local:OurViewModel}">
        <local:OurView />
    </DataTemplate> 
    This DataTemplate tells WPF that, any time we say to directly render an instance of OurViewModel, it should construct an instance of OurView, place it at that location, and set the DataContext of the OurView instance to the instance of OurViewModel.  Basically, WPF will do all of the work for us, just be specifying a DataTemplate.
    
    

     

    The way I was doing it from scratch is setting the datacontext to an instance of the ViewModel created in a class. IN your sample you are doing it wit datatemplate


    Thnaks for clarification


    Your knowledge is enhanced by that of others.
    Friday, November 4, 2011 5:30 PM
  • There are various ways of handling the mapping from ViewModel->View.  The approach I was taking here is a ViewModel first style of MVVM.  This tends to be a bit nicer from a developer's standpoint, though less "designer friendly", especially with blend.

     

    If you look at the same project (you can download it on the last page), you'll see how it's setup.  Basically, the above works great if you want to have nested views inside of a View, and the nested views may be different types.  It allows you to have a single "parent' ViewModel with a View, and then the parent can just set the "content" by setting a property on itself (which can just be defined as Object), and the data template will cause any bound content presenter to map up automatically...

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Sheldon _Xiao Wednesday, November 16, 2011 9:34 AM
    Friday, November 4, 2011 5:34 PM
  • ok I have dowload your sample and understand the way you are doing it. In fact intead of binding the datacontext of the control to a view model Instance that would be host by a viewmodel locator, you are relying on DataTemplate binding in order to load the view and let WPF creating the instance.

    I thing this method is good if you do not want to take control other the creation of instances and rely on WPF layer to do it and if your viewmodel have no contructor, otherwise I guess this would be quite problematic.

    My own opinion of course :-)


    Your knowledge is enhanced by that of others.
    Friday, November 4, 2011 6:26 PM
  • Actually - it's the opposite.  This way is better if your ViewModels need specific construction, but the Views are "pure MVVM" (since they're being created by WPF).  

     

    I'm always creating the ViewModel explicitly, in code (from within another ViewModel).  This allows me to specifically create a VM for a specific Model, etc.  WPF never creates the ViewModel in my code - only the View (which is always purely defined in terms of binding).

     

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, November 4, 2011 6:36 PM
  • Hi serge,

    How about your concern?

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, November 14, 2011 11:52 AM
  • I get what I need thanks
    Your knowledge is enhanced by that of others.
    Monday, November 14, 2011 12:50 PM
  • Could I close this thread as "Answered"?
    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, November 14, 2011 1:13 PM