From dc6a6feb4955078b20a061909b0dadea524e6996 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 7 Dec 2014 15:43:15 +0100 Subject: [PATCH] Added AcceptsReturn and AcceptsTab to TextBox. --- Perspex.Controls/TextBox.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Perspex.Controls/TextBox.cs b/Perspex.Controls/TextBox.cs index 710617a708..792bf8464a 100644 --- a/Perspex.Controls/TextBox.cs +++ b/Perspex.Controls/TextBox.cs @@ -16,6 +16,12 @@ namespace Perspex.Controls public class TextBox : TemplatedControl { + public static readonly PerspexProperty AcceptsReturnProperty = + PerspexProperty.Register("AcceptsReturn"); + + public static readonly PerspexProperty AcceptsTabProperty = + PerspexProperty.Register("AcceptsTab"); + public static readonly PerspexProperty TextProperty = TextBlock.TextProperty.AddOwner(); @@ -36,6 +42,18 @@ namespace Perspex.Controls this.PointerPressed += this.OnPointerPressed; } + public bool AcceptsReturn + { + get { return this.GetValue(AcceptsReturnProperty); } + set { this.SetValue(AcceptsReturnProperty, value); } + } + + public bool AcceptsTab + { + get { return this.GetValue(AcceptsTabProperty); } + set { this.SetValue(AcceptsTabProperty, value); } + } + public int CaretIndex { get @@ -111,6 +129,22 @@ namespace Perspex.Controls break; + case Key.Enter: + if (this.AcceptsReturn) + { + goto default; + } + + break; + + case Key.Tab: + if (this.AcceptsTab) + { + goto default; + } + + break; + default: if (!string.IsNullOrEmpty(e.Text)) {