Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Call Command from Page.cs

$
0
0

Hi everyone

i have Login page with Button

private async Task ClickAsync(Button signinbutton)
{
signinbutton.IsEnabled = false;
RegisterButton.IsEnabled = false;
try
{
string HtmlText = GetHtmlFromUri("http://google.com");
if (HtmlText == "")
{
await DisplayAlert("خطأ", "لايوجد اتصال بالانترنت , يرجى المحاولة لاحقاً.", "حسناً");
}
else if (!HtmlText.Contains("schema.org/WebPage"))
{
//Redirecting since the beginning of googles html contains that
//phrase and it was not found
await DisplayAlert("خطأ", "لايوجد اتصال بالانترنت , يرجى المحاولة لاحقاً.", "حسناً");

            }
            else
            {
                UserDialogs.Instance.ShowLoading("");

                if (UsernameEntry.Text != null && PasswordEntry.Text != null)
                {
                    var AccessToken = await accountApi.Login(UsernameEntry.Text, PasswordEntry.Text);

                    if (AccessToken != null)
                    {
                        Settings.AccessToken = AccessToken;
                        UserDialogs.Instance.HideLoading();

                    ****    /// Here i want to call Command Login From ViewModel****
                    }
                    else
                    {
                        UserDialogs.Instance.HideLoading();
                        await DisplayAlert("تنبيه!!.", "خطأ في تسجيل الدخول", "حسنأ");
                    }

                }
                else
                {
                    UserDialogs.Instance.HideLoading();
                    await DisplayAlert("تنبيه!!", "فضلاً تأكد من الحقول", "حسنأ");
                }
            }
        }
        catch (Exception e)
        {
            await DisplayAlert("يرجى المحاولة لاحقاً.", e.Message.ToString(), "حسناً");
        }
        finally
        {
            UserDialogs.Instance.HideLoading();
            signinbutton.IsEnabled = true;
            RegisterButton.IsEnabled = true;
        }
    }

My View Model

public class SignInViewModel : BaseViewModel, ISignInViewModel
{
private INavigationService navigationService;
private string _email;
private string _error;
private string _password;

    public SignInViewModel()
    {
        var canLogin = this.WhenAny(x => x.Email, x => x.Password,
            (e, p) => !string.IsNullOrEmpty(e.Value) && !string.IsNullOrEmpty(p.Value));

        GoRegister = ReactiveCommand.CreateFromTask(async () =>
           await navigationService.NavigateAsync(typeof(ISignUpViewModel)));

        Login = ReactiveCommand.CreateFromTask(async () =>
            {
                await navigationService.NavigateToMainPage(typeof(IMainViewModel));
            }, canLogin);

    }


    public string Error
    {
        get => _error;
        set => this.RaiseAndSetIfChanged(ref _error, value);
    }

    public ICommand GoRegister { get; }


    public ICommand Login { get; } // **Calll This Command **


    public string Email
    {
        get => _email;
        set => this.RaiseAndSetIfChanged(ref _email, value);
    }

    public string Password
    {
        get => _password;
        set => this.RaiseAndSetIfChanged(ref _password, value);
    }

    public override string Title => "تسجيل دخول";
}

I tried execute() but not worked

my Goal is to navigation to another View Using navigation service

Any Help Please

Thanks in Advance


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>