views:

57

answers:

2

I am familar with MVVM. Actually been doing most of my learning in SL4. However, with a recent need, I have to use SL3. I am attempting to use MVVM Light v3 with SL3 and utilize commanding. The problem is that in SL3 there is no Command attribute for buttons. I managed to find an old article (http://blog.galasoft.ch/archive/2009/09/26/using-relaycommands-in-silverlight-and-wpf.aspx), but I am having trouble figuring out the ButtonBaseExtensions.Command. It appears it is no longer available in GalaSoft.MvvmLight even though the namespace GalaSoft.MvvmLight.Command is.

So the question is how can I use MVVM Light v3 with SL3 and leverage commanding? Do I use MVVM Light v2? Can v2 and v3 coexist on the same machine?

Thx

B_W

A: 

You can use the EventToCommand behavior to still do commanding with buttons in Silverlight 3.

Matt Casto
A: 

I tried just adding a comment, but it did not work.

The EventToCommand behavior worked perfectly.

    <Button x:Name="btnLoad" Content="Load Products" HorizontalAlignment="Left" 
                Margin="8,0,0,3" VerticalAlignment="Bottom" Width="129">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
                <cmd:EventToCommand Command="{Binding LoadProductsCommand}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </Button>

Now I have another question. This works great by itself. I tried adding this inside a datagrid. The button shows but it does not trigger the command. Is there another solution for SL3 commanding within datagrids?

B_W