From face85f0dedf2bcd03a38eced501af3378e2dd1d Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 12 Jun 2015 00:08:36 +0200 Subject: [PATCH] Added AccessText.AccessKey. --- Perspex.Controls/Primitives/AccessText.cs | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Perspex.Controls/Primitives/AccessText.cs b/Perspex.Controls/Primitives/AccessText.cs index cc86128214..4bc06853a4 100644 --- a/Perspex.Controls/Primitives/AccessText.cs +++ b/Perspex.Controls/Primitives/AccessText.cs @@ -6,6 +6,7 @@ namespace Perspex.Controls.Primitives { + using System; using Perspex.Media; /// @@ -27,6 +28,23 @@ namespace Perspex.Controls.Primitives AffectsRender(ShowAccessKeyProperty); } + /// + /// Initializes a new instance of the class. + /// + public AccessText() + { + this.GetObservable(TextProperty).Subscribe(this.TextChanged); + } + + /// + /// Gets the access key. + /// + public char AccessKey + { + get; + private set; + } + /// /// Gets or sets a value indicating whether the access key should be underlined. /// @@ -104,5 +122,25 @@ namespace Perspex.Controls.Primitives return text.Substring(0, position) + text.Substring(position + 1); } } + + /// + /// Called when the property changes. + /// + /// The new text. + private void TextChanged(string text) + { + if (text != null) + { + int underscore = text.IndexOf('_'); + + if (underscore != -1 && underscore < text.Length - 1) + { + this.AccessKey = text[underscore + 1]; + return; + } + } + + this.AccessKey = (char)0; + } } }