RadContextMenu CommandParamenter doesnt 'work

2 posts, 1 answers
  1. Daniele
    Daniele avatar
    7 posts
    Member since:
    May 2014

    Posted 22 Mar 2015 Link to this post

    Hi,
    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:RadContextMenu.ContextMenu>
    <telerikPrimitives:RadContextMenu>
                                    <telerikPrimitives:RadContextMenuItem Content="Modifica" Command="{Binding Modifica}" CommandParameter="{Binding}"/>
                                     <telerikPrimitives:RadContextMenuItem Content="Rimuovi" Command="{Binding Rimuovi}" CommandParameter="{Binding}"/>
                                </telerikPrimitives:RadContextMenu>
    </telerikPrimitives:RadContextMenu.ContextMenu>

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


    This is my viewmodel code:

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

    }
    ));
    }
    }
  2. Answer
    Ves
    Admin
    Ves avatar
    2879 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,
    Ves
    Telerik
     

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

     
  3. DevCraft banner
Back to Top