public void Focus() { try { if (CurrentFocus != this) { CurrentFocus?.Blur(false); CurrentFocus = this; if (!IsFocused) { _isFocused = true; this.RaiseEvent(nameof(GotFocus), EventArgs.Empty); this.OnPropertyChanged(nameof(IsFocused)); } } Device.Thread.ExecuteOnMainThread(() => { Focusable = true; FocusableInTouchMode = true; DroidFactory.ShowKeyboard(this); }); } catch (ObjectDisposedException) { _isFocused = false; /*GULLPPPP!!*/ } }
public void Blur(bool closeKeyboard, bool fireLostFocus = true) { try { if (closeKeyboard) { var imm = (InputMethodManager)Context.GetSystemService(Context.InputMethodService); imm.HideSoftInputFromWindow(WindowToken, HideSoftInputFlags.None); } if (IsFocused) { _isFocused = false; if (fireLostFocus) { this.RaiseEvent(nameof(LostFocus), EventArgs.Empty); } this.OnPropertyChanged(nameof(IsFocused)); } Device.Thread.ExecuteOnMainThread(() => { // Set CurrentFocus before calling ClearFocus(), since // gainFocus is passed as true to OnFocusChanged. var focusRef = CurrentFocus; CurrentFocus = this; ClearFocus(); CurrentFocus = focusRef == this ? null : focusRef; Focusable = false; FocusableInTouchMode = false; }); } catch (ObjectDisposedException) { _isFocused = false; /*GULLPPPP!!*/ } }