Created
May 1, 2017 19:57
-
-
Save cjlotz/ea7b03ca03571bb665ac7cd5890187d7 to your computer and use it in GitHub Desktop.
TextChanged Event
This file contains 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
private bool _subscribed; | |
public EventHandler TextChanged; | |
protected override void OnAttachedToWindow() | |
{ | |
base.OnAttachedToWindow(); | |
Control.AfterTextChanged += HandleAfterTextChanged; | |
_subscribed = true; | |
} | |
protected override void OnDetachedFromWindow() | |
{ | |
base.OnDetachedFromWindow(); | |
Control.AfterTextChanged -= HandleAfterTextChanged; | |
_subscribed = false; | |
} | |
protected override void Dispose(bool disposing) | |
{ | |
if (disposing) | |
{ | |
if (Control != null && _subscribed) | |
{ | |
Control.AfterTextChanged -= HandleAfterTextChanged; | |
_subscribed = false; | |
} | |
} | |
base.Dispose(disposing); | |
} | |
private void HandleAfterTextChanged(object sender, EventArgs e) | |
{ | |
TextChanged?.Invoke(this, e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment