Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How to pass multiple parameters using command interface ?

$
0
0

I'm new with Xamaring.Forms and I'm building an app with a login page. On the XAML code of the page i have two Entries (username and password) and a Button. I'd like to send the two parameters of the entries on my LoginViewModel class when the user clicks on the button using the command interface in order to implement correctly the MVVM design pattern.

So far I was able to make it work with one parameter using CommandParameter :

<StackLayout x:Name="entryForm" >
      <Entry x:Name="nameEntry" Placeholder="Name" Keyboard="Default"    />
      <Entry x:Name="pwdEntry" Placeholder="Password" Keyboard="Default" IsPassword="True"/>
      <Button x:Name="loginButton"
              Text="Login"
              Command="{Binding LoginCommand}"
              CommandParameter="{Binding Source={x:Reference nameEntry},
                                  Path=Text}"  /> 
    </StackLayout>

the LoginViewModel class :

public class LoginViewModel : ViewModelBase {
        public LoginViewModel() {
            LoginCommand = new Command<string>(execute: (string parameter) => 
            {
                //do something with the string username
                    });
        }
        public ICommand LoginCommand {
            get;
            private set;
        }
    }

I know that Multibinding is not available on Xamarin.Forms but is there any other way to do it with the command interface ? I've tried to use a converter class to build a List or a custom LoginData class and use it in my LoginCommand but without success.


Viewing all articles
Browse latest Browse all 89864

Trending Articles