Ahmed Sayed
Ahmed Sayed

Reputation: 465

how to execute command before eventhandler

an eventhandler for button

private async void Btn_Clicked(object sender, EventArgs e)
{

}

and I have also command for the same button inside the viewModel

public Command LoginCommand
{
    get
    {
        return new Command(async () =>
        {

        });
    }

}

the problem is I want to use validation on value(consumed from Api) that returned inside the command and the Navigation lies inside the Event Handler so it Navigate before Validation so how execute command before eventhandler

Upvotes: 2

Views: 154

Answers (1)

David Pilkington
David Pilkington

Reputation: 13620

Commands have a CanExecute method that you can use for validation. You pass in a predicate to the constructor and it execute that if you were to call

LoginCommand.CanExecute(this);

You can pass in any object into that method.

This seems to be the best fit for you.

Upvotes: 2

Related Questions