Issue
I have a service class
public async Task LoginAsync(string userName, string password)
{
var model = new
{
phoneNum = userName,
passwordUs = password
};
.............
}
Page1.xaml.cs. This is how I call the service class
private ApiServices _apiServices = new ApiServices();
public ICommand LoginCommand { get; set; }
async void btone_Clicked(object sender, EventArgs e)
{
LoginCommand = new Command(async () => {
await _apiServices.LoginAsync(txtone.Text, txttwo.Text);
});
}
Looks like my code is wrong, so it doesn't call the service class
I want when button click event it will call LoginAsync
I have created a ViewModel, and that works fine, however I don't want to go through the ViewModel. (Maybe for some reason I want to check right where the button click event is). Thank you!
Solution
you are creating a command - this is only needed if you want to bind a command to a button, it is not needed when assigning an event handler
async void btone_Clicked(object sender, EventArgs e)
{
LoginCommand = new Command(async () => {
await _apiServices.LoginAsync(txtone.Text, txttwo.Text);
});
}
instead just call the method directly
async void btone_Clicked(object sender, EventArgs e)
{
await _apiServices.LoginAsync(txtone.Text, txttwo.Text);
}
Answered By - Jason
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.