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

Data bind Button.CommandParameterProperty to Entry.Text in Code Behind

$
0
0

Hi

Please translate the following (from https://forums.xamarin.com/discussion/43904/how-to-pass-multiple-parameters-using-command-interface)

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

to how it should be implemented in code; specifically, how to data bind the loginButton.CommandParameter to nameEntry.Text so that it (the text) gets passed as parameter to the Command in the ViewModel:

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;
        }
}

Thanks!


Viewing all articles
Browse latest Browse all 75885

Trending Articles