Forum Xamarin Xamarin.Forms

Binding IsVisible is not working

Hello I have this simple example to hide the forms elements after a command is called

The XMAL:
<Button Text="Iniciar" Command="{Binding DoLogin,Mode=TwoWay}" IsVisible="{Binding IsVisible,Mode=TwoWay}" />

The View Model Code:

         public Command DoLogin { get; }
                public UserVM()
                {
                    DoLogin = new Command(async () => await Login());
                }
         private bool isVisible = true;
                public bool IsVisible
                {
                    get { return isVisible; }
                    set
                    {
                        isVisible = value;
                        OnPropertyChanged();
                    }
                }
                public async Task Login()
                {
                       IsVisible = false;
                      Task.Delay(5000);
                       IsVisible = true;

                }

The Problem is the button never disappears , thx in advance

Best Answers

Answers

  • luiscarreroluiscarrero USMember ✭✭

    Hello @JoeManke , thx for your response, in fact it works, but when I change the code to the login process stop working again

                   isVisible = true;
                            return;
                        }
                        var user = new User
                        {
                            UserName = userAccounts.UserName,
                            Password = userAccounts.Password,
                            DeviceToken = "",
                            DeviceType = platform
                        };
                        var client = new RestClient(AppSettings.Domain);
    
                        var request = new RestRequest("api/User/Login", Method.POST);
                        request.AddHeader("ZintagmaToken", AppSettings.ZintagmaToken);
    
                        var json = JsonConvert.SerializeObject(user);
                        request.AddParameter("application/json", json, ParameterType.RequestBody);
    
                        var response = await client.ExecuteTaskAsync<User>(request);
                        if (response.StatusCode != System.Net.HttpStatusCode.Unauthorized)
                        {
                            App.IsUserLoggedIn = true;
                            App.user = response.Data;
                            App.token = response.Data.Token;
                            App.Current.MainPage = new MainPage();
                        }
                        else
                        {
                            Message = "Usuario o contraseña incorrectos";
                            UserAccounts.Password = string.Empty;
                        }
                   isVisible = true;
    
  • luiscarreroluiscarrero USMember ✭✭
    Accepted Answer

    I see my error , IsVisible instead isVisible thx @JoeManke

  • JoeMankeJoeManke USMember ✭✭✭✭✭
    edited August 2019

    That's why I always name private fields with an underscore (e.g. _isVisible), makes it easier to catch things like that.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Or use PropertyChanged.Fody
Sign In or Register to comment.