Issue
In my Xamarin App, for Navigation, I made the ImageButton, Label e.t.c clickable as Button. But the problem is, that if someone clicks the Label, ImageButton, Button rapidly (more than once), the Page appears multiple time.
I want to prevent this behavior, user shouldn't be able to click more than once.
For Button, in ViewModel, I used the UserDialogs.Instance.Loading("wait") as well, but if user clicks rapidly, the button get clicked more than once before the UserDialogs Instance appears.
Label
<Label x:Name="label">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding LabelCommand}"
NumberOfTapsRequired="1" />
</Label.GestureRecognizers>
</Label>
Button
<Button x:Name="button"
Command="{Binding ButtonCommand}" />
Solution
Disable the Button/Label for 2 Seconds using await Task.Delay(), when it's clicked.
For Button
<Button x:Name="button"
Command="{Binding ButtonCommand}"
IsEnabled="True"
Clicked="buttonClicked" />
public async void buttonClicked(object sender, EventArgs args)
{
button.IsEnabled = false;
await Task.Delay(2000);
button.IsEnabled = true;
}
For Label using TapGestureRecognizer
<Label x:Name="label"
IsEnabled="True">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding LabelCommand}"
Clicked="labelClicked"
NumberOfTapsRequired="1" />
</Label.GestureRecognizers>
</Label>
public async void labelClicked(object sender, EventArgs args)
{
label.IsEnabled = false;
await Task.Delay(2000);
label.IsEnabled = true;
}
Answered By - Stavrogin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.