Files
Artemis/src/Artemis.UI.Shared/Behaviors/PutCursorAtEndTextBoxBehavior.cs
T
SpoinkyNL 8718d01eae Core - Flattened namespaces
Shared UI - Flattened namespaces
Shared UI - General housekeeping
Project - Code cleanup
2020-09-01 00:14:08 +02:00

34 lines
832 B
C#

using System.Windows;
using System.Windows.Controls;
using Microsoft.Xaml.Behaviors;
namespace Artemis.UI.Shared
{
public class PutCursorAtEndTextBoxBehavior : Behavior<UIElement>
{
private TextBox _textBox;
protected override void OnAttached()
{
base.OnAttached();
_textBox = AssociatedObject as TextBox;
if (_textBox == null) return;
_textBox.GotFocus += TextBoxGotFocus;
}
protected override void OnDetaching()
{
if (_textBox == null) return;
_textBox.GotFocus -= TextBoxGotFocus;
base.OnDetaching();
}
private void TextBoxGotFocus(object sender, RoutedEventArgs routedEventArgs)
{
_textBox.CaretIndex = _textBox.Text.Length;
}
}
}