This is a migrated thread and some comments may be shown as answers.

RadContextMenu CommandParamenter doesnt 'work

1 Answer 83 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Daniele
Top achievements
Rank 1
Daniele asked on 22 Mar 2015, 04:27 PM
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
                            }

}
));
}
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 25 Mar 2015, 02:34 PM
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.

 
Tags
ContextMenu
Asked by
Daniele
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or