我向堆栈布局中添加了一个手势识别器,并且它不会每次都触发。我需要多次单击才能触发该事件。
xaml:
<StackLayout Orientation="Horizontal">
<ImageButton Source="someimage.png" BackgroundColor="Transparent" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
<StackLayout HorizontalOptions="EndAndExpand" Spacing="10" Orientation="Horizontal">
<StackLayout Spacing="0" x:Name="name1">
<Image Source="someimage.png" Grid.Column="0" Grid.Row="0"/>
<Label Text="some text" Grid.Column="0" Grid.Row="1" FontSize="8" TextColor="White" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Image Source="someimage.png" Grid.Column="0" Grid.Row="2"/>
<Label Text="text" Grid.Column="0" Grid.Row="3" FontSize="8" TextColor="White" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Command="{Binding Animate}" CommandParameter="{x:Reference name1}"/>
</StackLayout.GestureRecognizers>
</StackLayout>
</StackLayout>
viewmodel:
public ICommand Animate
{
get => new Command<StackLayout>(async (stack) => {
uint timeout = 50;
await stack.TranslateTo(-15, 0, timeout);
await stack.TranslateTo(15, 0, timeout);
await stack.TranslateTo(-9, 0, timeout);
await stack.TranslateTo(9, 0, timeout);
await stack.TranslateTo(-5, 0, timeout);
await stack.TranslateTo(5, 0, timeout);
await stack.TranslateTo(-2, 0, timeout);
await stack.TranslateTo(2, 0, timeout);
stack.TranslationX = 0;
});
}