A simple solution is the one given in the previous answer.
However, if you want to go further, then you can add a custom binding by implementing something like:
public class MvxUITextFieldShouldReturnTargetBinding : MvxTargetBinding { private ICommand _command; protected UITextField View { get { return Target as UITextField; } } public MvxUITextFieldShouldReturnTargetBinding(UITextField target) : base(target) { target.ShouldReturn = HandleShouldReturn; } private bool HandleShouldReturn(UITextField textField) { if (_command == null) return false; var text = textField.Text; if (!_command.CanExecute(text)) return false; textField.ResignFirstResponder(); _command.Execute(text); return true; } public override MvxBindingMode DefaultMode { get { return MvxBindingMode.OneWay; } } public override void SetValue(object value) { var command = value as ICommand; _command = command; } public override System.Type TargetType { get { return typeof(ICommand); } } protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); if (isDisposing) { var editText = View; if (editText != null) { editText.ShouldReturn = null; } } } }
which you could register during installation:
registry.RegisterCustomBindingFactory<UITextField>("ShouldReturn", textField => new MvxUITextFieldShouldReturnTargetBinding(textField));
I think this will work - it should allow you to bind MvxCommand or MvxCommand<string>
For more information on user bindings, see N = 28 at http://mvvmcross.wordpress.com
source share