Permalink
Browse files

Move mnemonic textbox caret to the end

  • Loading branch information...
lontivero committed Nov 5, 2018
1 parent 3211c4e commit 5dc35a2cca970ca11e58d105af78edfe31f2ca09
@@ -0,0 +1,46 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Threading;
using Avalonia.Xaml.Interactivity;
using System;
using System.Reactive.Disposables;
using System.Threading.Tasks;
namespace WalletWasabi.Gui.Behaviors
{
internal class PutCursorAtEndTextBoxBehavior: Behavior<TextBox>
{
private TextBox _textBox;
protected override void OnAttached()
{
base.OnAttached();
_textBox = AssociatedObject as TextBox;
if (_textBox == null)
{
return;
}
_textBox.PropertyChanged += TextInput;
}
protected override void OnDetaching()
{
if (_textBox == null)
{
return;
}
_textBox.PropertyChanged -= TextInput;
base.OnDetaching();
}
private void TextInput(object sender, AvaloniaPropertyChangedEventArgs args)
{
if(args.Property.Name == "Text")
Task.Delay(100).ContinueWith(x=>
Dispatcher.UIThread.InvokeAsync(()=>_textBox.CaretIndex = _textBox.Text.Length + 1));
}
}
}
@@ -15,6 +15,7 @@
<controls:ExtendedTextBox Text="{Binding MnemonicWords}" Watermark="MnemonicWords" UseFloatingWatermark="True" >
<i:Interaction.Behaviors>
<behaviors:MnemonicSuggestionBehavior SuggestionItems="{Binding Suggestions}" />
<behaviors:PutCursorAtEndTextBoxBehavior />
</i:Interaction.Behaviors>
</controls:ExtendedTextBox>
<ItemsControl Items="{Binding Suggestions}">

0 comments on commit 5dc35a2

Please sign in to comment.