Search code examples
buttonmvvmxamarin.formscommandmvvmcross

Xamarin.Forms buttons become disabled after touched


I use Xamarin.Forms and MvvmCross, but I've encountered a problem in applications. Buttons become disabled sometimes after touched and running the commands.

I added IsEnabled="True" to button but nothing changed

<Button 
    WidthRequest="36" 
    HeightRequest="36" 
    CornerRadius="18" 
    BorderWidth="2" 
    FontSize="18" 
    Text="{Binding OptionText}" 
    Command="{Binding OptionSelectedCommand}" 
    CommandParameter="{Binding .}" 
    IsEnabled="True" 
    VerticalOptions="Center" 
    HorizontalOptions="Center"/>

I want this button to be enabled always.

My Command code is:

new MvxAsyncCommand(async () => 
{ 
    if (option.IsSelected) 
    { 
        option.IsSelected = false; 
    } 
    else 
    { 
        option.OptionGroup.Options.ForEach(c => c.IsSelected = false);
        option.IsSelected = true; 
    } 

    return Task.CompletedTask; 
})

Solution

  • Finally I found a solution about this problem. Problem is related to MvxAsyncCommand, solved by using Command instead of MvxAsyncCommand.

    I think MvvmCross MvxAsyncCommand has a bug about running asynchronous methods