Skip to content

Instantly share code, notes, and snippets.

@cjlotz
Created May 1, 2017 19:57
Show Gist options
  • Save cjlotz/ea7b03ca03571bb665ac7cd5890187d7 to your computer and use it in GitHub Desktop.
Save cjlotz/ea7b03ca03571bb665ac7cd5890187d7 to your computer and use it in GitHub Desktop.
TextChanged Event
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