make it more efficient
MODIFY
WalletWasabi.Fluent/Behaviors/TagBoxAutoCompleteBoxBehavior.cs
WalletWasabi.Fluent/Behaviors/TagBoxAutoCompleteBoxBehavior.cs
@@ -12,13 +12,13 @@ namespace WalletWasabi.Fluent.Behaviors
{
public class TagBoxAutoCompleteBoxBehavior : Behavior<AutoCompleteBox>
{
- public static readonly StyledProperty<Action> CommitTextActionProperty =
- AvaloniaProperty.Register<SplitViewAutoBehavior, Action>(nameof(CommitTextAction));
+ public static readonly StyledProperty<Action<string>> CommitTextActionProperty =
+ AvaloniaProperty.Register<SplitViewAutoBehavior, Action<string>>(nameof(CommitTextAction));
public static readonly StyledProperty<Action> BackspaceAndEmptyTextActionProperty =
AvaloniaProperty.Register<SplitViewAutoBehavior, Action>(nameof(BackspaceAndEmptyTextAction));
- public Action CommitTextAction
+ public Action<string> CommitTextAction
{
get => GetValue(CommitTextActionProperty);
set => SetValue(CommitTextActionProperty, value);
@@ -42,7 +42,6 @@ namespace WalletWasabi.Fluent.Behaviors
AssociatedObject.Focus();
});
-
base.OnAttached();
}
@@ -52,7 +51,8 @@ namespace WalletWasabi.Fluent.Behaviors
if (obj.Length > 1 && !string.IsNullOrEmpty(obj.Trim()) && obj.EndsWith(' '))
{
- CommitTextAction?.Invoke();
+ CommitTextAction?.Invoke(AssociatedObject?.Text?.Trim() ?? "");
+ Dispatcher.UIThread.Post(() => { AssociatedObject?.ClearValue(AutoCompleteBox.TextProperty); });
}
}
@@ -62,17 +62,19 @@ namespace WalletWasabi.Fluent.Behaviors
{
BackspaceAndEmptyTextAction?.Invoke();
}
- else if (e.Key == Key.Enter && !string.IsNullOrEmpty(AssociatedObject?.Text.Trim() ?? ""))
+ else if (e.Key == Key.Enter && !string.IsNullOrEmpty(AssociatedObject?.Text?.Trim() ?? ""))
{
- CommitTextAction?.Invoke();
+ CommitTextAction?.Invoke(AssociatedObject?.Text?.Trim() ?? "");
+ Dispatcher.UIThread.Post(() => { AssociatedObject?.ClearValue(AutoCompleteBox.TextProperty); });
}
}
protected override void OnDetaching()
{
base.OnDetaching();
- AssociatedObject.TextChanged -= OnTextChanged;
+
AssociatedObject.KeyUp -= OnKeyUp;
+ AssociatedObject.TextChanged -= OnTextChanged;
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/Controls/TagBox.xaml
WalletWasabi.Fluent/Controls/TagBox.xaml
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
- <Button Command="{Binding AddTag}">Add</Button>
- <Button Command="{Binding RemoveTag}">Sub</Button>
</StackPanel>
</ControlTemplate>
</Setter>
</Style>
- <Style Selector="c|TagBox /template/ TextBox#PART_InputBox">
- <Setter Property="Opacity" Value="1" />
+ <Style Selector="c|TagBox /template/ AutoCompleteBox">
+ <Setter Property="Opacity" Value="0.5" />
</Style>
</Styles>
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/Controls/TagBox.xaml.cs
WalletWasabi.Fluent/Controls/TagBox.xaml.cs
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using Avalonia;
using Avalonia.Controls;
-using Avalonia.Controls.Primitives;
-using Avalonia.Input;
-using Avalonia.Layout;
-using Avalonia.Media;
-using Avalonia.Threading;
-using DynamicData;
-using WalletWasabi.Fluent.ViewModels.TagsBox;
namespace WalletWasabi.Fluent.Controls
{
@@ -18,121 +6,6 @@ namespace WalletWasabi.Fluent.Controls
/// </summary>
public class TagBox : ContentControl
{
- // public static readonly StyledProperty<int> MinimumPrefixLengthProperty =
- // AvaloniaProperty.Register<TagBox, int>(nameof(MinimumPrefixLength));
- //
- // public static readonly StyledProperty<IEnumerable> SuggestionsProperty =
- // AvaloniaProperty.Register<TagBox, IEnumerable>(nameof(Suggestions));
- //
- // private AutoCompleteBox _tb;
- //
- //
- // private WrapPanel _wp;
- //
- // public int MinimumPrefixLength
- // {
- // get => GetValue(MinimumPrefixLengthProperty);
- // set => SetValue(MinimumPrefixLengthProperty, value);
- // }
- //
- // public IEnumerable Suggestions
- // {
- // get => GetValue(SuggestionsProperty);
- // set => SetValue(SuggestionsProperty, value);
- // }
- protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
- {
- base.OnPropertyChanged(change);
-
- // if (change.Property == IsDialogOpenProperty)
- // {
- // PseudoClasses.Set(":open", change.NewValue.GetValueOrDefault<bool>());
- // }
- }
-
- protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
- {
- // _wp = e.NameScope.Find<WrapPanel>("PART_Container");
- ;
- // var dt = new TagBoxViewModel();
- // DataContext = dt;
- // dt.AppendedObject = "Always at the end";
- //
- // dt.Tags = new ObservableCollection<object>();
- //
- // dt.Tags.AddRange(new List<object>
- // {
- // new TagViewModel("asdasdas"),
- // new TagViewModel("asdasdas"),
- // new TagViewModel("asdasdas"),
- // new TagViewModel("asdasdas"),
- // new TagViewModel("asdasdas"),
- // new TagViewModel("asdasdas"),
- // new TagViewModel("asdasdas")
- // });
- //
- //
- // var b1 = e.NameScope.Find<Button>("PART_add");
- //
- // b1.Click += delegate { dt.Tags.Add(new TagViewModel("asdasdas")); };
- //
- // var b2 = e.NameScope.Find<Button>("PART_sub");
- //
- // b2.Click += delegate
- // {
- // if (dt.Tags.Count > 0)
- // dt.Tags.Remove(dt.Tags.Last());
- // };
-
- // // _tb = e.NameScope.Find<AutoCompleteBox>("PART_InputBox"); ;
- // // _tb.KeyUp += OnKeyPress;
- // // _tb.GetObservable<string>(TextBox.TextProperty).Subscribe(TextChanged);
- }
-
- // private void TextChanged(string obj)
- // {
- // if (obj.Length > 1 && !string.IsNullOrEmpty(obj.Trim()) && obj.EndsWith(' '))
- // {
- // var index = _wp.Children.Count - 1;
- //
- // _wp.Children.Insert(index, GenerateTag(obj, index));
- //
- // Dispatcher.UIThread.InvokeAsync(() => { _tb.Text = string.Empty; });
- // }
- // }
-
- // public IControl GenerateTag(string Text, int index)
- // {
- // return new Border
- // {
- // BorderThickness = new Thickness(1),
- // Margin = new Thickness(5),
- // Padding = new Thickness(5),
- // BorderBrush = new SolidColorBrush(Colors.LightGreen),
- // Child = new TextBlock
- // {
- // HorizontalAlignment = HorizontalAlignment.Center,
- // VerticalAlignment = VerticalAlignment.Center,
- // Text = Text.Trim()
- // }
- // };
- // }
- //
- // private void OnKeyPress(object? sender, KeyEventArgs e)
- // {
- // if (e.Key == Key.Back && _tb.Text.Length == 0 && _wp.Children.Count > 1)
- // {
- // _wp.Children.RemoveAt(_wp.Children.Count - 2);
- // }
- // else if (e.Key == Key.Enter && !string.IsNullOrEmpty(_tb.Text.Trim()))
- // {
- // var index = _wp.Children.Count - 1;
- //
- // _wp.Children.Insert(index, GenerateTag(_tb.Text, index));
- //
- // Dispatcher.UIThread.InvokeAsync(() => { _tb.Text = string.Empty; });
- // }
- // }
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/TagsBox/TagBoxViewModel.cs
WalletWasabi.Fluent/ViewModels/TagsBox/TagBoxViewModel.cs
-using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -13,9 +12,10 @@ namespace WalletWasabi.Fluent.ViewModels.TagsBox
{
public class TagBoxViewModel : ViewModelBase
{
- private ObservableAsPropertyHelper<IEnumerable<object>> _combinedContent;
+ private readonly ObservableAsPropertyHelper<IEnumerable<object>> _combinedContent;
+
+ private IEnumerable _suggestions;
private ObservableCollection<TagViewModel> _tags;
- public TagInputViewModel TagInput { get; }
public TagBoxViewModel()
{
@@ -33,7 +33,7 @@ namespace WalletWasabi.Fluent.ViewModels.TagsBox
Tags.Clear();
}
- private IEnumerable _suggestions;
+ public TagInputViewModel TagInput { get; }
public IEnumerable Suggestions
{
@@ -57,10 +57,7 @@ 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/ViewModels/TagsBox/TagInputViewModel.cs
WalletWasabi.Fluent/ViewModels/TagsBox/TagInputViewModel.cs
using System;
using System.Collections;
-using AvalonStudio.MVVM;
using ReactiveUI;
using WalletWasabi.Gui.ViewModels;
@@ -8,14 +7,10 @@ namespace WalletWasabi.Fluent.ViewModels.TagsBox
{
public class TagInputViewModel : ViewModelBase
{
+ private readonly TagBoxViewModel _parent;
private readonly ObservableAsPropertyHelper<IEnumerable> _suggestions;
-
- private string _inputText;
- private Action _CommitTextAction;
private Action _backspaceAndEmptyTextAction;
- private TagBoxViewModel _parent;
-
- public IEnumerable Suggestions => _suggestions.Value;
+ private Action<string> _commitTextAction;
public TagInputViewModel(TagBoxViewModel parent)
{
@@ -23,37 +18,32 @@ namespace WalletWasabi.Fluent.ViewModels.TagsBox
_suggestions = _parent.WhenAnyValue(x => x.Suggestions)
.ToProperty(this, x => x.Suggestions);
- this.CommitTextAction += OnCommitTextAction;
- this.BackspaceAndEmptyTextAction += OnBackspaceAndEmptyTextAction;
+ CommitTextAction += OnCommitTextAction;
+ BackspaceAndEmptyTextAction += OnBackspaceAndEmptyTextAction;
}
- private void OnBackspaceAndEmptyTextAction()
- {
- _parent.RemoveTag();
- }
+ public IEnumerable Suggestions => _suggestions.Value;
- private void OnCommitTextAction()
+ public Action<string> CommitTextAction
{
- _parent.AddTag(InputText.Trim());
- InputText = string.Empty;
+ get => _commitTextAction;
+ set => this.RaiseAndSetIfChanged(ref _commitTextAction, value);
}
- public string InputText
+ public Action BackspaceAndEmptyTextAction
{
- get => _inputText;
- set => this.RaiseAndSetIfChanged(ref _inputText, value);
+ get => _backspaceAndEmptyTextAction;
+ set => this.RaiseAndSetIfChanged(ref _backspaceAndEmptyTextAction, value);
}
- public Action CommitTextAction
+ private void OnBackspaceAndEmptyTextAction()
{
- get => _CommitTextAction;
- set => this.RaiseAndSetIfChanged(ref _CommitTextAction, value);
+ _parent.RemoveTag();
}
- public Action BackspaceAndEmptyTextAction
+ private void OnCommitTextAction(string tagString)
{
- get => _backspaceAndEmptyTextAction;
- set => this.RaiseAndSetIfChanged(ref _backspaceAndEmptyTextAction, value);
+ _parent.AddTag(tagString);
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/TagsBox/TagViewModel.cs
WalletWasabi.Fluent/ViewModels/TagsBox/TagViewModel.cs
-using System;
using ReactiveUI;
using WalletWasabi.Gui.ViewModels;

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 Text="{Binding InputText, Mode=TwoWay}" Items="{Binding Suggestions}">
+ <AutoCompleteBox Items="{Binding Suggestions}">
<i:Interaction.Behaviors>
<behaviors:TagBoxAutoCompleteBoxBehavior
CommitTextAction="{Binding CommitTextAction, Mode=TwoWay}"

make it more efficient