Created
October 7, 2013 12:44
-
-
Save slodge/6867280 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MvxEditTextFocusChangeTextSpecialTargetBinding | |
| : MvxAndroidTargetBinding | |
| { | |
| protected EditText EditText | |
| { | |
| get { return (EditText)Target; } | |
| } | |
| private bool _subscribed; | |
| public MvxEditTextFocusChangeTextSpecialTargetBinding(EditText view) | |
| : base(view) | |
| { | |
| SubscribeToEvents(); | |
| } | |
| protected override void SetValue(object value) | |
| { | |
| var editText = EditText; | |
| if (editText == null) | |
| return; | |
| value = value ?? string.Empty; | |
| editText.Text = value.ToString(); | |
| } | |
| public override MvxBindingMode DefaultMode | |
| { | |
| get { return MvxBindingMode.TwoWay; } | |
| } | |
| public void SubscribeToEvents() | |
| { | |
| var editText = EditText; | |
| if (editText == null) | |
| return; | |
| editText.FocusChange += HandleFocusChange; | |
| _subscribed = true; | |
| } | |
| private void HandleFocusChange(object sender, View.FocusChangeEventArgs e) | |
| { | |
| var editText = EditText; | |
| if (editText == null) | |
| return; | |
| if (!e.HasFocus) | |
| FireValueChanged(editText.Text); | |
| } | |
| public override Type TargetType | |
| { | |
| get { return typeof(string); } | |
| } | |
| protected override void Dispose(bool isDisposing) | |
| { | |
| if (isDisposing) | |
| { | |
| var editText = EditText; | |
| if (editText != null && _subscribed) | |
| { | |
| editText.FocusChange -= HandleFocusChange; | |
| _subscribed = false; | |
| } | |
| } | |
| base.Dispose(isDisposing); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment