Reputation: 2161
If I want to implement the MVVM patern. What is the correct procedure for implementing a event such as DoubletTapped on TextBlock inside a Datatemplate of a ListView.ItemTemplate?
<ListView.ItemTemplate>
<DataTemplate x:DataType="classes:Person">
<TextBlock
DoubleTapped="{x:Bind}"//what goes here to call a method on the ViewModel
Foreground="Green"
Text="{x:Bind Name}" />
</DataTemplate>
</ListView.ItemTemplate>
Upvotes: 0
Views: 116
Reputation: 1595
Please modify your TextBlock
Xaml as below:
<TextBlock Foreground="Green" Text="{x:Bind Name}" >
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="DoubleTapped">
<core:InvokeCommandAction Command="{Binding ElementName=RootPage, Path=DataContext.YourCommandMethod}"/>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</TextBlock>
RootPage
is the name of Root Element, which in my case is a Page
.
Upvotes: 2