add text autocomplete
MODIFY
WalletWasabi.Fluent/Behaviors/TagBoxAutoCompleteBoxBehavior.cs
WalletWasabi.Fluent/Behaviors/TagBoxAutoCompleteBoxBehavior.cs
@@ -34,6 +34,7 @@ namespace WalletWasabi.Fluent.Behaviors
{
AssociatedObject.KeyUp += OnKeyUp;
AssociatedObject.TextChanged += OnTextChanged;
+ AssociatedObject.DropDownClosed += OnDropDownClosed;
Dispatcher.UIThread.InvokeAsync(() =>
{
@@ -45,11 +46,32 @@ namespace WalletWasabi.Fluent.Behaviors
base.OnAttached();
}
+ private void OnDropDownClosed(object? sender, EventArgs e)
+ {
+ var currentText = AssociatedObject?.Text ?? "";
+ var selItem = AssociatedObject?.SelectedItem as string;
+
+ if (currentText.Length == 0)
+ {
+ return;
+ }
+
+ if (selItem is null || selItem.Length == 0) return;
+
+ CommitTextAction?.Invoke(AssociatedObject?.Text?.Trim() ?? "");
+ AssociatedObject?.ClearValue(AutoCompleteBox.SelectedItemProperty);
+
+ Dispatcher.UIThread.Post(() =>
+ {
+ AssociatedObject?.ClearValue(AutoCompleteBox.TextProperty);
+ });
+ }
+
private void OnTextChanged(object? sender, EventArgs e)
{
- var obj = AssociatedObject?.Text ?? "";
+ var currentText = AssociatedObject?.Text ?? "";
- if (obj.Length > 1 && !string.IsNullOrEmpty(obj.Trim()) && obj.EndsWith(' '))
+ if (currentText.Length >= 1 && !string.IsNullOrEmpty(currentText.Trim()) && currentText.EndsWith(' '))
{
CommitTextAction?.Invoke(AssociatedObject?.Text?.Trim() ?? "");
Dispatcher.UIThread.Post(() => { AssociatedObject?.ClearValue(AutoCompleteBox.TextProperty); });
@@ -58,7 +80,7 @@ namespace WalletWasabi.Fluent.Behaviors
private void OnKeyUp(object? sender, KeyEventArgs e)
{
- if (e.Key == Key.Back && AssociatedObject?.Text.Length == 0)
+ if (e.Key == Key.Back && (AssociatedObject?.Text?.Length == 0 || AssociatedObject?.Text is null))
{
BackspaceAndEmptyTextAction?.Invoke();
}
@@ -72,6 +94,7 @@ namespace WalletWasabi.Fluent.Behaviors
protected override void OnDetaching()
{
base.OnDetaching();
+ AssociatedObject.DropDownClosed -= OnDropDownClosed;
AssociatedObject.KeyUp -= OnKeyUp;
AssociatedObject.TextChanged -= OnTextChanged;
}

MODIFY
WalletWasabi.Fluent/ViewModels/TagsBox/TagBoxViewModel.cs
WalletWasabi.Fluent/ViewModels/TagsBox/TagBoxViewModel.cs
@@ -65,7 +65,10 @@ namespace WalletWasabi.Fluent.ViewModels.TagsBox
public void RemoveTag()
{
- if (Tags.Any()) Tags.Remove(Tags.Last());
+ if (Tags.Any())
+ {
+ Tags.Remove(Tags.Last());
+ }
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/Views/TagsBox/TagInputView.xaml
WalletWasabi.Fluent/Views/TagsBox/TagInputView.xaml
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:behaviors="clr-namespace:WalletWasabi.Fluent.Behaviors;assembly=WalletWasabi.Fluent"
x:Class="WalletWasabi.Fluent.Views.TagsBox.TagInputView">
- <AutoCompleteBox x:DataType="vm:TagInputViewModel" Items="{CompiledBinding Suggestions}">
+ <AutoCompleteBox x:DataType="vm:TagInputViewModel" IsTextCompletionEnabled="True" Items="{CompiledBinding Suggestions}">
<i:Interaction.Behaviors>
<behaviors:TagBoxAutoCompleteBoxBehavior
CommitTextAction="{CompiledBinding CommitTextAction}"

add text autocomplete