Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoginViewModel : ViewModelBase
- {
- private string _username;
- private string _password;
- public RelayCommand LoginButtonCommand { get; private set; }
- public bool CanExecuteLoginCommand { get; set; }
- public LoginViewModel()
- {
- LoginButtonCommand = new RelayCommand(HandleLoginButtonCommand, () => CanExecuteLoginCommand);
- CanExecuteLoginCommand = true;
- }
- public string Username
- {
- get
- {
- return _username;
- }
- set
- {
- _username = value;
- RaisePropertyChanged(() => Username);
- }
- }
- public string Password
- {
- get
- {
- return _password;
- }
- set
- {
- _password = value;
- RaisePropertyChanged(() => Password);
- }
- }
- private void HandleLoginButtonCommand()
- {
- CanExecuteLoginCommand = false;
- //Validate login?
- CanExecuteLoginCommand = true;
- }
- }
- public partial class LoginViewController : UIViewController
- {
- private Binding _usernameTextFieldBinding;
- private Binding _passwordTextFieldBinding;
- private LoginViewModel _viewModel;
- public LoginViewController(IntPtr handle) : base(handle)
- {
- }
- public override void ViewDidLoad()
- {
- base.ViewDidLoad();
- _viewModel = Application.Locator.Login;
- HideKeyboardHandling(UsernameTextField);
- HideKeyboardHandling(PasswordTextField);
- _usernameTextFieldBinding = this.SetBinding(
- () => _viewModel.Username)
- .ObserveSourceEvent("EditingDidEnd")
- .WhenSourceChanges(() => _viewModel.Username = UsernameTextField.Text);
- _passwordTextFieldBinding = this.SetBinding(
- () => _viewModel.Username)
- .ObserveSourceEvent("EditingDidEnd")
- .WhenSourceChanges(() => _viewModel.Password = PasswordTextField.Text);
- Loginbutton.SetCommand("TouchUpInside", _viewModel.LoginButtonCommand);
- }
- public override void DidReceiveMemoryWarning()
- {
- base.DidReceiveMemoryWarning();
- // Release any cached data, images, etc that aren't in use.
- }
- void HideKeyboardHandling(UITextField textField)
- {
- textField.ShouldReturn = TextField =>
- {
- TextField.ResignFirstResponder();
- return true;
- };
- var gesture = new UITapGestureRecognizer(() => View.EndEditing(true));
- gesture.CancelsTouchesInView = false;
- View.AddGestureRecognizer(gesture);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement