error using waitActivityIndicator, how to resolve?

Asked

Viewed 47 times

1

I am making a connection via web api in my application, so it is not accepting the use of "waitActivityIndicator", indicates that it does not exist in the current context, below my code, someone could tell me how to solve this:

using EbsHelpDesk.Models;
using EbsHelpDesk.Services;
using EbsHelpDesk.Views;
using Newtonsoft.Json;
using System;
using System.Collections.ObjectModel;
using System.Net.Http;
using Xamarin.Forms;

namespace EbsHelpDesk.Views
{
    public partial class LoginPage : TabbedPage
    {

        public LoginPage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);

        }

        protected async void BtnLogin_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(emailEntry.Text))
            {
                await DisplayAlert("Erro", "Digite um nome de usuário válido", "Aceitar");
                emailEntry.Focus();
                return;
            }
            if (string.IsNullOrEmpty(senhaEntry.Text))
            {
                await DisplayAlert("Erro", "Digite uma senha", "Aceitar");
                emailEntry.Focus();
                return;
            }
            this.logar();


            App.Current.MainPage = new MainPageRoot();
        }

        private async void logar()
        {
            waitActivityIndicator.IsRunning = true;
            var loginRequest = new LoginRequest
            {
                Usuario = emailEntry.Text,
                Senha = senhaEntry.Text,
            };
            var JsonRequest = JsonConvert.SerializeObject(loginRequest);
            var httpContent = new StringContent(JsonRequest);
            var resp = string.Empty;

            try
            {
                var client = new HttpClient();
                client.BaseAddress = new Uri("http://ativoproject.ebasesistemas.com.br");
                var url = "/login";
                var result = await client.PostAsync(url, httpContent);

                if (!result.IsSuccessStatusCode)
                {
                    await DisplayAlert("Erro", "Usuario ou senha incorretos", "Aceitar");
                    waitActivityIndicator.IsRunning = false;
                    return;
                }

                resp = await result.Content.ReadAsStringAsync();
            }
            catch (Exception ex)
            {
                await DisplayAlert("Erro", ex.Message, "Aceitar");
                waitActivityIndicator.IsRunning = false;
                return;

            }

            var user = JsonConvert.DeserializeObject<UserName>(resp);
            waitActivityIndicator.IsRunning = false;
            await DisplayAlert("Bem vindo","vc esta logado", "Aceitar");
        }
    }
}
  • 1

    Only one use of waitActivityIndicator and his statement in XAML would be necessary for us to evaluate. But Ativityindicator in XAML?

  • 1

    Yes, I understood that I had to declare it in my shampoo.... I insert and it went all right, thank you!

  • 1

    put as reply your comment for me approve!!

1 answer

1


It is necessary to declare the ActivityIndicator in your XAML, stating the name as you want to use.

In your case it would be something like this:

<ActivityIndicator x:Name="waitActivityIndicator "
                   IsRuning="False"
                   IsVisible="False"/>

In this case, when XAML is compiled it will create a variable of type ActivityIndicator with that name that will be linked to the screen component.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.