Hide the Button when the Status Changed in Xamarin

I have Implemented a Button, which calls for a function. That function actually sends a request to server to issue a credential. When user receives a Credential, Status of Credential is Offered, but when s/he clicks on This Button, it sends a request to server and the Status of Button change to Received.

I only wants to Show the Button when the Status of Button is Offered.

CredentialPage.xml

<Button x:Name="Button_Round" WidthRequest="40" HeightRequest="40" CornerRadius="20" BorderWidth="2" TextColor="White" BorderColor="Teal" BackgroundColor="Teal" Text="Accept Offer" Command="{Binding ProcessOffer}" /> 

CredentialViewModel.cs => CreateRequestAsync() is the one, which sends request to server. When the request is sent successfully, I want to hide the button.

    public ICommand ProcessOffer => new Command(async () =>     {         try         {             //await _poolConfigurator.ConfigurePoolsAsync();             var agentContext = await _agentContextProvider.GetContextAsync();             var credentialRecord = await _credentialService.GetAsync(agentContext, _credential.Id);             var connectionId = credentialRecord.ConnectionId;             var connectionRecord = await _connectionService.GetAsync(agentContext, connectionId);             (var request, _) = await _credentialService.CreateRequestAsync(agentContext, _credential.Id);             await _messageService.SendAsync(agentContext.Wallet, request, connectionRecord);             await DialogService.AlertAsync("Request has been sent to the issuer.", "Success", "Ok");         }         catch (Exception e)         {             await DialogService.AlertAsync("Pool is not correctly configured. Please add proper genesis file.\n("+e.Message+")","Pool Error","Ok");         }     }); 

If you could guide me, It will be very kind of you 🙂

Add Comment
1 Answer(s)

bind the IsVisible property to a VM property

<Button x:Name="Button_Round"  IsVisible="{Binding ButtonVisible}" ... /> 

then in your VM (your VM must implement INotifyPropertyChanged)

private bool _ButtonVisible = true;  public bool ButtonVisible {   get {     return _ButtonVisible;   }   set {      _ButtonVisible = value;      PropertyChanged("ButtonVisible");   }  } 

then whenever your receive the response from the server, you can set ButtonVisible to the appropriate value

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.