开发者

eventocommand not working

I am making one application in MVVM using Galasoft MVVM Light toolkit. However i can't make EventToCommand make it work with Telerik Context Menu. Here is my code :-

   <ListBox x:Name="lstPhotoAlbums" ItemsSource="{Binding AlbumsCollection}" 
                         Margin="3,0" Grid.Row="1" ItemsPanel="{StaticResource wrapPanelItemsPanelTemplate}"
                         ItemTemplate="{StaticResource ListboxPhotosDataTemplate}" 
                         ItemContainerStyle="{StaticResource ListboxPhotoAlbumsContainerStyle}" Height="500" HorizontalAlignment="Left" VerticalAlignment="Top" Width="178">
                        <telerik:RadContextMenu.ContextMenu>
                            <telerik:RadContextMenu x:Name="albumsCtxMenu">
                                <telerik:RadMenuItem Header="Delete" >
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Click">
                                            <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding DeleteAlbumCommand}"  CommandParameter="{Binding SelectedItem, ElementName=lstPhotoAlbums}"/>
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </telerik:RadMenuItem>
                            </teler开发者_开发知识库ik:RadContextMenu>
                        </telerik:RadContextMenu.ContextMenu>
                    </ListBox>

I do hit the breakpoint in my viewmodel. However the command parameter is always null. Any ideas where i am wrong?

Thanks in advance :)


As this is an old post, you might have found the answer to your question. However, as I was trying to do the same, I did not find a precis answer to this and if others are looking for the same, I hope this might help them.

You will need to remove the CommandParameter argument from your EventToCommand and change it to this:

<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding DeleteAlbumCommand}" PassEventArgsToCommand="True" />

Your RelayCommand in your ViewModel or whereever you are implementing your RelayCommand would have to look something like this:

RelayCommand<EventArgs> DeleteAlbumCommand = new RelayCommand<EventArgs>(CallbackMethod);

CallbackMethod should then look something like this:

private void CallbackMethod(EventArgs eventArgs)
{
...
}

Hope this will help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜