Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Silverlight TV 13: MVVM Light Toolkit

Download

Right click “Save as…”

Silverlight MVP Laurent Bugnion of IdentityMine appears on the show to discuss using MVVM with Silverlight. Laurent and John discuss their experiences with MVVM and how Laurent's experiences inspired him to create his MVVM Light Toolkit. If you have been meaning to get into MVVM or you feel a bit overwhelmed by it all, definitely watch this episode and check out the MVVM Light Toolkit. 

Follow @SilverlightTV on Twitter for the latest updates.

Tags:

Follow the Discussion

  • Thanks John & Laurent; Great show!

    One question for Laurent. Let's someone creates a solution using RIA Services template, which adds a few nice items for authorization and etc. Now you have your solution and projects created. Then you decide to use MVVM Light, since you can't start creating a new solution to choose MVVM light templates, how do you get to add all the features MVVM light templates to an already created solution?

     

    Secondly what would be the advantage of using MVVM light over Prism4 and the same question in the opposite direction, what is advantage of using Prism 4 over MVVM light?

     

    Thanks!

  • Laurent Bugnionlbugnion Laurent Bugnion

    Hi Ben, and thanks!

     

    About your first question: Adding the MVVM Light to an application is actually very easy, and I am preparing a blog post showing how to do that. I will publish this ASAP. It is a matter of adding the DLL and then wiring up the objects together in XAML (or in Blend...)

     

    The main advantage of MVVM Light over Prism is that it is lighter and easier to add in an application. Also, it is very strongly aimed to Blendability, and all the components are created with this in mind. I generally recommend the following: If you have an application using Prism already (for its composition features for example), then it might make more sense to use the Prism components for the MVVM application, in order to avoid adding too many dependencies. If you don't, I would rather recommend MVVM Light, because it is lighter and easier.

     

    Hope this helps!

    Laurent

  • John Papajopapa Evangelist on the Loose

    Ben - Here is a very quick rundown of Prism compared to MVVM Light, all off my head in 3 minutes Angel

    Feature MVVM Light Toolkit Prism
    Commanding help Included Included
    Event Messenger Included Included
    ViewModel Locator Included Not included
    Regions Not included Yes
    DI Not included Yes - Unity
    WPF/Silverlight Multi Targeting     Not Included Yes
    Module Catalogs Not included Yes

     

    However, keep in mind that you can still handle regions on your own with MVVM Light Toolkit, use MEF or Unity or Ninject with it, and use MEF for moduel catalogs. So either choice is excellent depending on what you need.

     

    This is a short overview ... I'll be sure to post more MVVM details on my blog at johnpapa.net and Silverlight TV since it is one of my favorite topics.

  • M-V-VM Light support for Blendability is absolutely awesome, think that use of MEF in future versions can simplify it further and easily add support to Regions and Catalog like feature.

  • Gentlemen, thank you for detail replies;

    John, I was thinking of the same as far as using MEF for Modules and Regions, since I like it's implementation better than Prism. However, in my original post I purposely post fixed Prism with "4" since many things are going to change compared to 2, including of MEF’s finding modules.

    I think it would be good to bring one of the PMs from Prism team to SLTV to talk about Prism 4.

  • John Papajopapa Evangelist on the Loose

    Ben - It would be good. I'll see if we can get some Prism 4 love .

  • Ali DaneshmandiAli1 Ali Daneshmandi

    Hi Laurent,

     

    Thanks for this great toolkit. Your toolkit is nice but if you add a single how to use documentation to it, it would be awesome. I know you did most of it in blog posts but if you gather them in a single doc it would be great. Thanks.

     

    One question I have is about the Locator Class. Could you please explain more about this class and how it does the work.

    It might be a stupid question but Why when I do not use the locator class and just Bind the DataContext of the main container object to the VM such as below the Command do not executed.

     

    <UserControl 

                xmlns:vm="clr-namespace:MyApp.ViewModels"

                xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                 xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras">

     

    <UserControl.Resources>

                <vm:MainPageViewModel x:Key="MainPageViewModel"/>

    </UserControl.Resources>

     

    <Grid DataContext="{Binding MainPageViewModel}">

          <Button Content="Simple Command">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <cmd:EventToCommand Command="{Binding SimpleCommand}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
          </Button>

    </Grid>

    </UserControl>

     

    and in the MainPageViewModel class

     

    namespace MyApp.ViewModels
    {
        public class MainPageViewModel: ViewModelBase
        {

              public MainPageViewModel()
              {

                   SimpleCommand= new RelayCommand(() =>
                   {
                     // do sth

                    Status = "SimpleCommand executed";
                  });

              }

     

            public RelayCommand SimpleCommand
            {
                get;
                private set;
            }

    }

     

    As you see I have set the DataContext of the Grid to my VM so my button should be able to use the SimpleCommand, am I right?

     

    Nore: The above code is just a sample. I know that the button now has built in command support now in SL4.

     

    Thanks!

  • Laurent Bugnionlbugnion Laurent Bugnion

    Hi Ali,

     

    In your sample, you declared the MainViewModel as a resource. Hence, you must bind to the resource, using the StaticResource extension.

     

    <Grid DataContext="{Binding Source={StaticResource MainPageViewModel}}">

     

    This is a fairly simple way to create and bind your data context, but it has a few disadvantages that the Locator solves:

     

    - You cannot pass parameters to the ViewModel constructor.

    - You don't have control over the creation (and deletion) of the ViewModel. The parser will create it when the line in the resources is reached (in Silverlight... in WPF the ViewModel is created when it is used by a StaticResource extension). This makes it impossible to create the ViewModel beforehand, for example when the application starts.

     

    I hear you about the documentation. I am busy writing my next book now, so it won't be before a moment, but I have a series of posts titled MVVM Light 101 showing how to get started with each component. Great idea gathering them all in a single page. I am also going to extract the XML documentation from the code to document the API in an easier way.

     

    Thanks

    Laurent

  • Laurent Bugnionlbugnion Laurent Bugnion

    Hey John,

     

    Not sure what you mean with WF/SL code sharing. The MVVM Light Toolkit uses exactly the same syntax (and about 80% of the same code Wink) in WPF and in Silverlight. This is one of the strength of the framework actually. I am very careful to keep the code compatible.

     

    Cheers,

    Laurent

  • John Papajopapa Evangelist on the Loose

    Hi Laurent - Sorry for the confusion. I meant that Prism has multi-targeting features. http://msdn.microsoft.com/en-us/library/dd458864.aspx

     

    I clarified my earlier post.

  • Ali DaneshmandiAli1 Ali Daneshmandi

    Thanks Laurent!

     

    You saved my day. I am working on a SL4 app and I am going to use your MVVM Light, am I allowed to do it? Smiley

     

    Thanks again for the help!

  • Great content, thanks! 

     

    John, when watching the vids in full screen mode, the vs ide is always blurry.  Can you fix that in future vids?  It's terribly difficult to see the code.

     

    Thanks!

  • Ross Wozniakrwozniak Ross Wozniak

    Nice job Laurent and John.

     

    I'm currently using MEF to 'import' my view model class instances. The advantage of this is that it keeps the instance hanging around in memory, so if I leave a page (view) and come back, I can restore the state of the page based on state that I've stored in the view model.

     

    Is there any way to achieve this w/ your toolkit, or is such that if I leave a view and come back, the view model will be reinstantiated, and I will have lost all state information?

     

    Thanks,

    Ross

  • John Papajopapa Evangelist on the Loose

    Aaron1 - Thanks for the feedback. We're looking into some changes to make the screen capture and resolution crisper.

  • Ross, why wouldn't you continue using MEF's container and catalog system the way you are now? This is one of the best parts of MEF.

     

    ..Ben

  • Ross Wozniakrwozniak Ross Wozniak

    Hi Ben,

     

    I agree. I don't have any plans to change the way I'm doing it currently, but the only downside (that I can see) to instantiating the view model instances w/ MEF is that you lose design-time support in Blend.

     

    This doesn't bother me personally, but some folks may like taking the approach of declaring the view model instance in their view's XAML, and setting the DataContext of the top-level container in the view to the view model (as Laurent does in this video)...so that it is Blend-friendly.

     

    Ross

  • Hi Laurent, Pappa,

     

    Thanks for this great video.

     

    I was wondering if you could provide the source code for this presentation including the WCF service to get the list of Customers object.

     

    What I am struggling the most is how to use the MVVM Light framework with WCF services and RIA services and I would appreciate your help.

     

    Also, it is possible to use RIA services as a real service with the .svc extention in a separate project so that we can deploy the RIA services in another server? 

     

    Cheers

     

    Claudio

  • Hi Laurent,

     

    Where can I find your posts titled MVVM Light 101?

     

    Cheers

     

    Claudio

  • Hi, i love the Light toolkit and your presentations are good, but cant start, its 3 days now and my hands are up. I need help! Please dont tell me to read the "getting started" because i have done so.
    I fully understand what MVVM means. i would like to use the MVVM light toolkit for all it presents in my Silverlight LOB Applications.

    I am using VS 2010 RC, SL4, WCF Ria Services with EntityFramework, and i am looking to access records from my EntityModel, show them in a datagrid and do some event actions on the datagrid too.
    Incidentaly i have ended up watching all the videos that present the tookit's usage and snooped around many blogs but i havent gotten help on this. I havent also seen a sample that uses SL4 and WCF Ria Services with the light toolkit.
    All the videos are pointed towards using a webservice(i dont know why!) and most blogs just show additions to the framework. I wanted to request you to always include a LOB sample in your presentations. Although i know developing software is hard and sometimes spoon-feeding is not good, samples like these may be useful in putting word out there and reduce the usage the pain in starting up.  

    I have posted a simple Sample that uses a simple Northwind Customers & Orders table on skydrive at:http://cid-5e33c7b2ca3aa2a9.skydrive.live.com/self.aspx/SilverLight%20Dev/MVVMLightToolKitSample01.rar ">http://cid-5e33c7b2ca3aa2a9.skydrive.live.com/self.aspx/SilverLight%20Dev/MVVMLightToolKitSample01.rar


    I get an error messange and seem to be confused with the observableCollections.

    Please download it and help me, i have spent 3 days trying this an no luck!

     

    thanks

    regards

    dooldots@gmail.com

     

  • IsaacIsaac

    Hello- 
    Thanks for the intro video!  I am VERY new to silverlight/blend and especially MVVM.  Is there anyway to get this source code?  Id would be a HUGE help to someone as junior as myself.  :)
    Thanks in advance!

  • MojamMojam

    Hi John,
    I am very new in silverlight. I am using Silverlight4. I want to create a project with silverliht4,MEF, MVVM and wcf Ria. For this reason I want to use MVVM light. can you please advice me about it and if you have any tutorial please send me asap.

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.