Browse Source

Added AccessText.AccessKey.

pull/58/head
Steven Kirk 11 years ago
parent
commit
face85f0de
  1. 38
      Perspex.Controls/Primitives/AccessText.cs

38
Perspex.Controls/Primitives/AccessText.cs

@ -6,6 +6,7 @@
namespace Perspex.Controls.Primitives
{
using System;
using Perspex.Media;
/// <summary>
@ -27,6 +28,23 @@ namespace Perspex.Controls.Primitives
AffectsRender(ShowAccessKeyProperty);
}
/// <summary>
/// Initializes a new instance of the <see cref="AccessText"/> class.
/// </summary>
public AccessText()
{
this.GetObservable(TextProperty).Subscribe(this.TextChanged);
}
/// <summary>
/// Gets the access key.
/// </summary>
public char AccessKey
{
get;
private set;
}
/// <summary>
/// Gets or sets a value indicating whether the access key should be underlined.
/// </summary>
@ -104,5 +122,25 @@ namespace Perspex.Controls.Primitives
return text.Substring(0, position) + text.Substring(position + 1);
}
}
/// <summary>
/// Called when the <see cref="Text"/> property changes.
/// </summary>
/// <param name="text">The new text.</param>
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;
}
}
}

Loading…
Cancel
Save