I'm new in using Xamarin and MVVM (Light) and I didn't found a good example on the internet for passing parameters from a view back to a ViewModel so I can execute the functionality there. In other words I'm looking for a way to link my ViewModel and View so I can execute my command from my ViewModel in the view. The problem is that I want to pass parameters with it back. Which seems to be a pain.
I have a very basic ViewModel
public ICommand RegisterUserAsyncCommand { get; set; }
private async void RegisterUserAsync(User userInfo)
{
string firstName = userInfo.FirstName;
string lastName = userInfo.LastName;
string email = userInfo.Email;
string password = userInfo.Password;
bool admin = userInfo.Admin;
//params = int, string, string, string, string, bool
User newUser = new User(null, firstName, lastName, email, password, admin);
}
public RegisterViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
_userDataService = new UserDataService(new UserWebservice());
//Commands
RegisterUserAsyncCommand = new RelayCommand<User>(RegisterUserAsync);
}
And my View
_firstNameTextView = FindViewById<TextView>(Resource.Id.activityRegisterFirstNameTextView);
_lastNameTextView = FindViewById<TextView>(Resource.Id.activityRegisterLastNameTextView);
_emailTextView = FindViewById<TextView>(Resource.Id.activityRegisterEmailTextView);
_passwordTextView = FindViewById<TextView>(Resource.Id.activityRegisterEmailTextView);
_confirmTextView = FindViewById<TextView>(Resource.Id.activityRegisterConfirmPasswordTextView);
_registerButton = FindViewById<Button>(Resource.Id.activityRegisterRegisterButton);
Binding registerBinding = this.SetBinding(() => ViewModel.Registration, () => new Registration(_firstNameTextView.Text, _lastNameTextView.Text, _emailTextView.Text, _passwordTextView.Text, _confirmTextView.Text, true)
);
_registerButton.SetCommand("Click", (GalaSoft.MvvmLight.Command.RelayCommand<GalaSoft.MvvmLight.Helpers.Binding>)ViewModel.RegisterUserAsyncCommand, registerBinding);
Can someone give me a clear and easy example or tell me what I'm doing wrong?