I am not sure if I am quite catching the idea behind the MVVM design specially regarding passing the data from viewmodel
->
view
and vice versa.
So for example let's say I have a model that has those properties (As simple as possible) :
public class User{
public string username {get; set;}
public string password {get; set;}
}
and here's my ViewModel
that has a login method:
// dependency injection
private readonly Context _context;
public constructor(Context context)
{
_context = context;
}
// my method to verify login:
public async Task<bool> login(string username, string password)
{
// fetching data
var user = await _context.Users.FirstOrDefaultAsync(p => p.username== username&& p.Password == password);
return (user != null);
}
so my question is: how should I deliver these methods to the view class?
I usually just do this inside the button_click()
:
Var viewmodel = new Viewmodels.User();
login_state = viewmodel.login(email, password);
However I just feel this isn't the right way as it'd make the design very tightly coupled. How should I implement it?