Lets say I have a ListView whose DataTemplate is a Grid. On the Grid I have a GestureRecognizer
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" Command="{Binding CmdTapped, Source={x:Reference root}}" CommandParameter="{Binding}" NumberOfTapsRequired="1" />
</Grid.GestureRecognizers>
Notice that I have a code-behind handler and a view model command tied to the recognizer.
The code-behind simply invokes a haptic
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
HapticFeedback.Default.Perform(HapticFeedbackType.Click);
}
The command simply sleeps for 5 seconds
private void RowSelected()
{
Thread.Sleep(5000);
}
When I run this on my iPhone and touch the grid, I see the code-behind get called right away but the vibration only happens after the viewmodel's 5 second wait.
I put this contrived example together because nothing I try affects the grid in the row of a ListView (or even a BindableTemplate) - color change, text change, haptic feedback - until after the viewmodel is done, which in my case is a PushAsync so the affect of the changes become moot when the new page appears.
Nothing changes if I remove the code-behind and put the haptic in the viewmodel just prior to the sleep. The haptic only vibrates when the command's handler exits. This is not useful if the command has some work to do and all you wanted to do is let the user know that work has begun.