public override bool OnKeyDown(Keycode keyCode, KeyEvent e) { if (keyCode == Keycode.Enter) { EventHandler <EventHandledEventArgs> rkp; if ((rkp = ReturnKeyPressed) != null) { var args = new EventHandledEventArgs(); rkp(Pair ?? this, args); if (args.IsHandled) { return(true); } } if (KeyboardReturnType > KeyboardReturnType.Next) { Blur(true); } } try { return(base.OnKeyDown(keyCode, e)); } catch (Exception ex) { Device.Log.Error(ex); return(false); } }
public bool OnItemLongClick(AdapterView parent, View view, int position, long id) { var args = new EventHandledEventArgs(); var cell = view as ICell; LongClicked?.Invoke(cell?.Pair ?? cell, args); return(args.IsHandled); }
public bool OnItemLongClick(AdapterView parent, View view, int position, long id) { Device.Log.Platform($"Cell long-clicked at position {position}"); var args = new EventHandledEventArgs(); var cell = RetrieveCell(view); LongClicked?.Invoke(cell?.Pair ?? cell, args); return(args.IsHandled); }
public TextArea() { AcceptsReturn = true; Padding = new System.Windows.Thickness(5); TextWrapping = TextWrapping.Wrap; VerticalScrollBarVisibility = ScrollBarVisibility.Auto; base.TextChanged += (o, e) => { if (base.Text != currentValue && !(expression == null || expression.IsMatch(base.Text))) { base.Text = currentValue; base.SelectionStart = currentValue.Length; return; } string oldValue = currentValue; currentValue = base.Text; OnPropertyChanged("Text"); OnPropertyChanged("StringValue"); var handler = TextChanged; if (handler != null) { handler(Pair ?? this, new ValueChangedEventArgs <string>(oldValue, currentValue)); } }; PreviewKeyDown += (o, e) => { if (e.Key == System.Windows.Input.Key.Return) { var handler = ReturnKeyPressed; if (handler != null) { var args = new EventHandledEventArgs(); handler(pair ?? this, args); e.Handled = args.IsHandled; } } }; Loaded += (o, e) => { if (setFocusOnLoad) { base.Focus(); } }; }
public TextBox() { Padding = new System.Windows.Thickness(5); base.TextChanged += (o, e) => { if (base.Text != currentValue && !(expression == null || expression.IsMatch(base.Text))) { base.Text = currentValue; base.Select(currentValue.Length, 0); return; } string oldValue = currentValue; currentValue = base.Text; OnPropertyChanged("Text"); OnPropertyChanged("StringValue"); var handler = TextChanged; if (handler != null) { handler(Pair ?? this, new ValueChangedEventArgs <string>(oldValue, currentValue)); } }; PreviewKeyDown += (o, e) => { if (e.Key == System.Windows.Input.Key.Return) { var handler = ReturnKeyPressed; if (handler != null) { var args = new EventHandledEventArgs(); handler(pair ?? this, args); e.Handled = args.IsHandled; } } }; Loaded += (o, e) => { if (setFocusOnLoad) { base.Focus(); } }; }
protected override void OnKeyUp(KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { var ret = ReturnKeyPressed; var args = new EventHandledEventArgs(); if (ret != null) { ret(Pair, args); } if (args.IsHandled) { e.Handled = true; return; } } base.OnKeyUp(e); }
public TextArea() { base.BackgroundColor = null; base.ShouldChangeText += delegate(UITextView textView, NSRange range, string text) { if (text == "\n") { var handler = ReturnKeyPressed; if (handler != null) { var args = new EventHandledEventArgs(); handler(pair ?? this, args); if (args.IsHandled) { return(false); } } } string value = currentValue ?? string.Empty; try { if (range.Length == 0) { value = value.Insert((int)value.Length, text); } else { value = value.Replace(value.Substring((int)range.Location, (int)range.Length), text); } } catch { value = string.Concat(value, text); } return(expression == null ? true : expression.IsMatch(value)); }; base.Changed += (sender, e) => { if (placeholderLabel != null) { placeholderLabel.Alpha = string.IsNullOrEmpty(Text) ? 1 : 0; } if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0) && SelectedTextRange != null) { // iOS 7 has a bug where the caret will stay below the bounds of the box. we need to compensate for it CGRect line = GetCaretRectForPosition(SelectedTextRange.Start); nfloat overflow = line.Y + line.Height - (ContentOffset.Y + Bounds.Height - ContentInset.Bottom - ContentInset.Top); if (overflow > 0) { var offset = ContentOffset; offset.Y += overflow + 7; UIView.Animate(0.2, () => { SetContentOffset(offset, true); }); } } var phandler = PropertyChanged; if (phandler != null) { phandler(this, new PropertyChangedEventArgs("Text")); phandler(this, new PropertyChangedEventArgs("StringValue")); } var handler = TextChanged; if (handler != null) { handler(Pair ?? this, new ValueChangedEventArgs <string>(currentValue, Text)); } currentValue = Text; }; base.Started += (sender, e) => { if (SelectedTextRange != null) { ScrollRectToVisible(GetCaretRectForPosition(SelectedTextRange.Start), true); } var phandler = PropertyChanged; if (phandler != null) { phandler(this, new PropertyChangedEventArgs("IsFocused")); } var handler = GotFocus; if (handler != null) { handler(pair ?? this, EventArgs.Empty); } }; base.Ended += (sender, e) => { var phandler = PropertyChanged; if (phandler != null) { phandler(this, new PropertyChangedEventArgs("IsFocused")); } var handler = LostFocus; if (handler != null) { handler(pair ?? this, EventArgs.Empty); } }; }
public PasswordBox() { base.SecureTextEntry = true; base.ClearButtonMode = UITextFieldViewMode.WhileEditing; base.AutocapitalizationType = UITextAutocapitalizationType.None; base.AutocorrectionType = UITextAutocorrectionType.No; base.VerticalAlignment = UIControlContentVerticalAlignment.Center; base.ShouldChangeCharacters += delegate(UITextField textField, NSRange range, string newString) { string value = currentValue ?? string.Empty; try { if (range.Length == 0) { value = value.Insert((int)value.Length, newString); } else { value = value.Replace(value.Substring((int)range.Location, (int)range.Length), newString); } } catch { value = string.Concat(value, newString); } return(expression == null ? true : expression.IsMatch(value)); }; base.EditingChanged += (sender, e) => { var phandler = PropertyChanged; if (phandler != null) { phandler(this, new PropertyChangedEventArgs("Password")); phandler(this, new PropertyChangedEventArgs("StringValue")); } var handler = PasswordChanged; if (handler != null) { handler(Pair ?? this, new ValueChangedEventArgs <string>(currentValue, Text)); } currentValue = Text; }; base.ShouldReturn += delegate { bool shouldReturn = true; var handler = ReturnKeyPressed; if (handler != null) { var args = new EventHandledEventArgs(); handler(pair ?? this, args); shouldReturn = !args.IsHandled; } if (shouldReturn) { ResignFirstResponder(); return(true); } return(false); }; base.EditingDidBegin += (sender, e) => { var phandler = PropertyChanged; if (phandler != null) { phandler(this, new PropertyChangedEventArgs("IsFocused")); } var handler = GotFocus; if (handler != null) { handler(pair ?? this, EventArgs.Empty); } }; base.EditingDidEnd += (sender, e) => { var phandler = PropertyChanged; if (phandler != null) { phandler(this, new PropertyChangedEventArgs("IsFocused")); } var handler = LostFocus; if (handler != null) { handler(pair ?? this, EventArgs.Empty); } }; }
public PasswordBox() { passwordBox = new System.Windows.Controls.PasswordBox(); passwordBox.Padding = new System.Windows.Thickness(5); passwordBox.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; passwordBox.Tag = this; passwordBox.PasswordChanged += (o, e) => { if (passwordBox.Password == currentValue) { // password boxes have a peculiar behavior where the cursor is pushed to the beginning // when used in a two-way binding. to compensate, we need to force the cursor to the end. var select = passwordBox.GetType().GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic); if (select != null) { select.Invoke(passwordBox, new object[] { currentValue.Length, 0 }); } return; } if (!(expression == null || expression.IsMatch(passwordBox.Password))) { passwordBox.Password = currentValue; var select = passwordBox.GetType().GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic); if (select != null) { select.Invoke(passwordBox, new object[] { currentValue.Length, 0 }); } return; } string oldValue = currentValue; currentValue = passwordBox.Password; var phandler = PropertyChanged; if (phandler != null) { phandler(this, new PropertyChangedEventArgs("Password")); phandler(this, new PropertyChangedEventArgs("StringValue")); } var handler = PasswordChanged; if (handler != null) { handler(Pair ?? this, new ValueChangedEventArgs <string>(oldValue, currentValue)); } }; passwordBox.PreviewKeyDown += (o, e) => { if (e.Key == System.Windows.Input.Key.Return) { var handler = ReturnKeyPressed; if (handler != null) { var args = new EventHandledEventArgs(); handler(pair ?? this, args); e.Handled = args.IsHandled; } } }; passwordBox.Loaded += (o, e) => { if (setFocusOnLoad) { passwordBox.Focus(); } }; passwordBox.GotFocus += (o, e) => { var phandler = PropertyChanged; if (phandler != null) { phandler(this, new PropertyChangedEventArgs("IsFocused")); } var handler = GotFocus; if (handler != null) { handler(pair ?? this, EventArgs.Empty); } }; passwordBox.LostFocus += (o, e) => { var phandler = PropertyChanged; if (phandler != null) { phandler(this, new PropertyChangedEventArgs("IsFocused")); } var handler = LostFocus; if (handler != null) { handler(pair ?? this, EventArgs.Empty); } }; }