0
votes

I'm working on a Windows Phone 8.1 Application and my tapped event is not firing when I click on an item in my ListView.

Do you have any idea on what's wrong here?

<Page.Resources>
    <DataTemplate x:Key="myItem">
        <StackPanel>
            <Grid>
                ...
                <i:Interaction.Behaviors>
                    <core:EventTriggerBehavior EventName="Tapped">
                        <core:InvokeCommandAction Command="{Binding ShowDetails}" />
                    </core:EventTriggerBehavior>
                </i:Interaction.Behaviors>
                ...
            </Grid>
        </StackPanel>
    </DataTemplate>
</Page.Resources>

<Pivot Title="Items" Margin="8">
    <PivotItem Header="All">
        <ListView ItemTemplate="{StaticResource myItem}"
                    ItemsSource="{Binding Items}"
                    Background="Transparent">
    </PivotItem>
</Pivot>

EDIT 1:

The problem is coming from the DataContext in my DataTemplate. In my DataTemplate the context is Item.

Is there a way to move back to the Page DataContext?

1

1 Answers

1
votes

So, what happens is that the item is trying to find ShowDetails command in the Item, when it's actually in the ViewModel?

In that case, you can bind to DataContext of the page.

Command="{Binding DataContext.ShowDetails, ElementName=PageName}"