How to get ClickedItem from GridView?

Feb 1, 2014 at 3:47 PM
In my View I have a GridView:
<GridView x:Name="mainGridView" ItemsSource="{Binding Posts}" IsItemClickEnabled="True" SelectionMode="None" Grid.Row="1">
                <triggers:EventTrigger EventName="ItemClick">
                    <triggers:InvokeCommandAction Command="{Binding GridViewItemClickCommand}"
                <DataTemplate x:Key="mainGridViewStyle">
                    <Grid x:Name="gridItem" Width="320" Height="240">
                        <Image x:Name="imageItem" Source="{Binding preview_url}" Stretch="UniformToFill"/>
                <StaticResource ResourceKey="mainGridViewStyle"/>
In my ViewModel I have a command:
public DelegateCommand GridViewItemClickCommand { get; private set; }
In my ViewModel constructor I have command initialization:
GridViewItemClickCommand = new DelegateCommand(() => navigationService.Navigate("Post",null));
How can I get ClickedItem after tapping/clicking GridView item?
Feb 4, 2014 at 5:15 PM

I am not aware of the implementation of the InvokeCommandAction you are using but if that action will pass the EventArgs of the event as the command parameter, then a possible way to recieve these args in the view model is to use the generic implementation of the DelegateCommand. The generic implementation allows you to recieve a parameter that will be passed to the "delegate" of the DelegateCommand. For example, if you redefine your DelegateCommand like this:
public DelegateCommand<ItemClickEventArgs> GridViewItemClickCommand { get; private set; }
Then you would be able to recieve the parameters like this (where e are the ItemClickEventArgs of the event):
this.GridViewItemClickCommand = new DelegateCommand<ItemClickEventArgs>( (e) => { /* Some code */ });
I hope this helps,

Damian Cherubini
Feb 4, 2014 at 5:55 PM
Thanks for your answer. I solved my problem by calling a method despite of using command.
I added this behavior to XAML element:
                <Core:EventTriggerBehavior EventName="ItemClick">
                    <Core:CallMethodAction MethodName="GridViewClick" 
                TargetObject="{Binding Mode=OneWay}" />
Then I added corresponding method to ViewModel:
public async void GridViewClick(object sender, object parameter)
var arg = parameter as ItemClickEventArgs;
// some code