Hello,
Welcome to our Microsoft Q&A platform!
3) The login-button is bound to a Command (or AsyncCommand in MVVM Helpers)
When the button is clicked, the command shall return a Model-Class
<LoginDataModel> with username and password as string.
4) Login-Page disappears, and the returned <LoginDataModel> is further processed
and sent to the API with httpclient
When the Login-Page disappears(popup from the stack), the ViewModel behind it will been released .
But if you want to keep the returned model (LoginDataModel
) for later usage, there are several methods to achieve this.
For example:
1.define the LoginDataModel
as a global class and a prefix for field UserName
and field Password
as ,for example:
public class LoginDataModel
{
public static string UserName { get; set; }
public static string Password { get; set; }
public LoginDataModel()
{
UserName = "";
Password = "";
}
}
2.When the command shall return a Model-Class, then the value of LoginDataModel
will been changed.And the value will not lost even if the Login-Page
be pop up from the page stack.
Then you can get the value of LoginDataModel
in any other class you want.
System.Diagnostics.Debug.WriteLine("Name = " + LoginDataModel.UserName +"<-----> pwd = " + LoginDataModel.Password);
Note:
Of course, you can also use MessagingCenter to achieve this.
You need to Publish a message ,Subscribe to a message as follows:
Publish a message
string[] values = { name, password};
MessagingCenter.Send<ViewModelBase, string[]> (this, "userInfo", values);
Subscribe to a message
MessagingCenter.Subscribe<ViewModelBase, string[]> (this, "userInfo", (sender, values) => {
DisplayAlert(values[0], values[1], "Ok");
});
Best Regards,
Jessie Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.