Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. public class LoginViewModel : ViewModelBase
  2. {
  3. private string _username;
  4. private string _password;
  5.  
  6. public RelayCommand LoginButtonCommand { get; private set; }
  7. public bool CanExecuteLoginCommand { get; set; }
  8.  
  9. public LoginViewModel()
  10. {
  11. LoginButtonCommand = new RelayCommand(HandleLoginButtonCommand, () => CanExecuteLoginCommand);
  12. CanExecuteLoginCommand = true;
  13. }
  14.  
  15. public string Username
  16. {
  17. get
  18. {
  19. return _username;
  20. }
  21. set
  22. {
  23. _username = value;
  24. RaisePropertyChanged(() => Username);
  25. }
  26. }
  27.  
  28. public string Password
  29. {
  30. get
  31. {
  32. return _password;
  33. }
  34. set
  35. {
  36. _password = value;
  37. RaisePropertyChanged(() => Password);
  38. }
  39. }
  40.  
  41. private void HandleLoginButtonCommand()
  42. {
  43. CanExecuteLoginCommand = false;
  44.  
  45. //Validate login?
  46.  
  47. CanExecuteLoginCommand = true;
  48. }
  49. }
  50.  
  51. public partial class LoginViewController : UIViewController
  52. {
  53. private Binding _usernameTextFieldBinding;
  54. private Binding _passwordTextFieldBinding;
  55. private LoginViewModel _viewModel;
  56.  
  57. public LoginViewController(IntPtr handle) : base(handle)
  58. {
  59. }
  60.  
  61. public override void ViewDidLoad()
  62. {
  63. base.ViewDidLoad();
  64. _viewModel = Application.Locator.Login;
  65.  
  66. HideKeyboardHandling(UsernameTextField);
  67. HideKeyboardHandling(PasswordTextField);
  68.  
  69. _usernameTextFieldBinding = this.SetBinding(
  70. () => _viewModel.Username)
  71. .ObserveSourceEvent("EditingDidEnd")
  72. .WhenSourceChanges(() => _viewModel.Username = UsernameTextField.Text);
  73. _passwordTextFieldBinding = this.SetBinding(
  74. () => _viewModel.Username)
  75. .ObserveSourceEvent("EditingDidEnd")
  76. .WhenSourceChanges(() => _viewModel.Password = PasswordTextField.Text);
  77.  
  78. Loginbutton.SetCommand("TouchUpInside", _viewModel.LoginButtonCommand);
  79. }
  80.  
  81. public override void DidReceiveMemoryWarning()
  82. {
  83. base.DidReceiveMemoryWarning();
  84. // Release any cached data, images, etc that aren't in use.
  85. }
  86.  
  87. void HideKeyboardHandling(UITextField textField)
  88. {
  89. textField.ShouldReturn = TextField =>
  90. {
  91. TextField.ResignFirstResponder();
  92. return true;
  93. };
  94.  
  95. var gesture = new UITapGestureRecognizer(() => View.EndEditing(true));
  96. gesture.CancelsTouchesInView = false;
  97. View.AddGestureRecognizer(gesture);
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement