Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
Using MVVM light toolkit with Menuitem
posted

Hi,

We are using t he MVVM light toolkit and want to attach a command to a menu item.

I've created the following XAML the event doesn't appear to be triggered.

Does anyone have any pointers?

Many thanks,

<ig:XamMenuItem Header="New" Height="33" HorizontalAlignment="Left"  Name="xamMenuItem1" VerticalAlignment="Center"  >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <cmd:EventToCommand Command="{Binding NewContactCommand, Mode=TwoWay}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
</ig:XamMenuItem>
Parents
No Data
Reply
  • 215
    posted

    Hi,

    I've had the same problem and fixed it.  It seems the XamMenuItem isn't aware of it's DataContext.  Try setting the data context on the XamMenuItem.  Here is my example:

     

     

                              <ig:XamMenuItem

                                    DataContext="{Binding RelatedPriorityGrid, Source={StaticResource Locator}}" 

                                    Name="AddPriority" 

                                    Header="Ajouter item sélectionné à mes priorités"

                                    IsEnabled="{Binding CanAddPriority}">

                                    <i:Interaction.Triggers>

                                        <i:EventTrigger EventName="Click">

                                            <cmd:EventToCommand PassEventArgsToCommand="True" Command="{Binding AddPriorityCommand}" />

                                        </i:EventTrigger>

                                    </i:Interaction.Triggers>

                                    <ig:XamMenuItem.Icon>

                                        <Image Source="Resources/Add.png"/>

                                    </ig:XamMenuItem.Icon>

                                </ig:XamMenuItem>

     

     

    Hope this helps!

     

     

    Yohan

Children
No Data