RadContextMenu CommandParamenter doesnt 'work

Thread is closed for posting
2 posts, 1 answers
  1. Daniele
    Daniele avatar
    7 posts
    Member since:
    May 2014

    Posted 22 Mar 2015 Link to this post

    I'm using the RadDataBoundListBox with a RadContextMenu inside.
    I would like to pass the item ,to my viewmodel, of the list box where I opened the menu.
    The command is fired but the paramenter is always null.
    I also read others thread but I didn't find any solution.

    This is my xaml code:
    <telerikPrimitives:RadDataBoundListBox x:Name="myLista" ItemContainerStyle="{StaticResource ItemContainerStyle}" ItemTemplate="{StaticResource ListBoxNewItemTemplate}" ItemsSource="{Binding ListaItems}">
                                    <telerikPrimitives:RadContextMenuItem Content="Modifica" Command="{Binding Modifica}" CommandParameter="{Binding}"/>
                                     <telerikPrimitives:RadContextMenuItem Content="Rimuovi" Command="{Binding Rimuovi}" CommandParameter="{Binding}"/>

    <i:EventTrigger EventName="ItemTap">
    <command:EventToCommand Command="{Binding ItemClick}"
    CommandParameter="{Binding SelectedItem, ElementName=myLista}"/>

    This is my viewmodel code:

    private RelayCommand<MyViewModel> _modifica;
    public RelayCommand<MyViewModel> Modifica
    return _modifica
                        ?? (_modifica = new RelayCommand<MyViewModel>(
    item =>
    if (item != null)
                                    ...do something

  2. Answer
    Ves avatar
    2917 posts

    Posted 25 Mar 2015 Link to this post

    Hi Daniele,

    All you need to do in this case is remove the CommandParameter attribute from the RadContextMenuItem definition:

    <telerikPrimitives:RadContextMenuItem Content="Modifica" Command="{Binding Modifica}" CommandParameter="{Binding}"/>

    The integration is provided out of the box and if no CommandParameter is set, the corresponding RadDataBoundListBoxItem is sent as command parameter. You can find a similar example in our examples solution -- its default installation folder looks like this:
    C:\Program Files (x86)\Telerik\UI for Windows Phone 8 Q1 2015\Examples
    Look for ContextMenu's FirstLook example in the examples.WindowsPhone\ContextMenu folder.

    Best regards,

    See What's Next in App Development. Register for TelerikNEXT.

Back to Top