diff --git a/Perspex.Controls/TextBox.cs b/Perspex.Controls/TextBox.cs index e6e7184cfc..9d532acc69 100644 --- a/Perspex.Controls/TextBox.cs +++ b/Perspex.Controls/TextBox.cs @@ -49,7 +49,6 @@ namespace Perspex.Controls this.GotFocus += (s, e) => this.textBoxView.GotFocus(); this.LostFocus += (s, e) => this.textBoxView.LostFocus(); this.KeyDown += this.OnKeyDown; - this.PointerPressed += this.OnPointerPressed; } public bool AcceptsReturn @@ -94,6 +93,31 @@ namespace Perspex.Controls set { this.SetValue(TextWrappingProperty, value); } } + protected override void OnPointerPressed(PointerEventArgs e) + { + var point = e.GetPosition(this.textBoxView); + this.CaretIndex = this.SelectionStart = this.SelectionEnd = + this.textBoxView.GetCaretIndex(point); + e.Device.Capture(this); + } + + protected override void OnPointerMoved(PointerEventArgs e) + { + if (e.Device.Captured == this) + { + var point = e.GetPosition(this.textBoxView); + this.CaretIndex = this.SelectionEnd = this.textBoxView.GetCaretIndex(point); + } + } + + protected override void OnPointerReleased(PointerEventArgs e) + { + if (e.Device.Captured == this) + { + e.Device.Capture(null); + } + } + protected override void OnTemplateApplied() { Decorator textContainer = this.GetVisualDescendents() @@ -398,12 +422,5 @@ namespace Perspex.Controls return pos - caretIndex; } - - private void OnPointerPressed(object sender, PointerEventArgs e) - { - var point = e.GetPosition(this.textBoxView); - this.CaretIndex = this.SelectionStart = this.SelectionEnd = - this.textBoxView.GetCaretIndex(point); - } } }