tag input box impl
MODIFY
WalletWasabi.Fluent/Controls/TagBox.xaml
WalletWasabi.Fluent/Controls/TagBox.xaml
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:c="clr-namespace:WalletWasabi.Fluent.Controls">
+ xmlns:c="clr-namespace:WalletWasabi.Fluent.Controls"
+
+ xmlns:vmt="clr-namespace:WalletWasabi.Fluent.ViewModels.TagsBox">
<Style Selector="c|TagBox">
<Setter Property="Template">
<ControlTemplate>
- <StackPanel>
-
- <ItemsRepeater Items="{Binding CombinedContent}">
- <ItemsRepeater.ItemTemplate>
- <DataTemplate>
- <ContentControl Content="{Binding .}" />
-
- </DataTemplate>
- </ItemsRepeater.ItemTemplate>
- <ItemsRepeater.Layout>
- <UniformGridLayout></UniformGridLayout>
- </ItemsRepeater.Layout>
- </ItemsRepeater>
+ <StackPanel x:DataType="vmt:TagBoxViewModel">
+ <ItemsControl Items="{CompiledBinding CombinedContent}">
+ <ItemsControl.ItemsPanel>
+ <ItemsPanelTemplate>
+ <WrapPanel />
+ </ItemsPanelTemplate>
+ </ItemsControl.ItemsPanel>
+ </ItemsControl>
<Button Command="{Binding AddTag}">Add</Button>
<Button Command="{Binding RemoveTag}">Sub</Button>
</StackPanel>

MODIFY
WalletWasabi.Fluent/ViewModels/RecoverWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/RecoverWalletPageViewModel.cs
@@ -11,12 +11,11 @@ namespace WalletWasabi.Fluent.ViewModels
public RecoveryPageViewModel(IScreen screen) : base(screen)
{
Title = "Recovery";
+ RecoveryWordsTagBox.Suggestions = new Mnemonic(Wordlist.English, WordCount.Twelve).WordList.GetWords();
}
public override string IconName => "home_regular";
public TagBoxViewModel RecoveryWordsTagBox { get; } = new TagBoxViewModel();
-
- public IEnumerable MnemonicSuggestions { get; } = new Mnemonic(Wordlist.English, WordCount.Twelve).WordList.GetWords();
}
}

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;
using System.Linq;
@@ -12,45 +13,41 @@ namespace WalletWasabi.Fluent.ViewModels.TagsBox
{
public class TagBoxViewModel : ViewModelBase
{
- private TagInputViewModel _tagInput;
-
private ObservableAsPropertyHelper<IEnumerable<object>> _combinedContent;
private ObservableCollection<TagViewModel> _tags;
+ public TagInputViewModel TagInput { get; }
public TagBoxViewModel()
{
- this.WhenAnyValue(x => x.Tags)
- .Where(x => x is { })
- .Subscribe(AddTagHandler);
+ _tags = new ObservableCollection<TagViewModel>();
- Tags = new ObservableCollection<TagViewModel>();
TagInput = new TagInputViewModel(this);
- }
- public IEnumerable<object> CombinedContent => _combinedContent.Value;
+ _combinedContent = Tags
+ .ToObservableChangeSet(x => x)
+ .ToCollection()
+ .Select(x => x.Append((object)TagInput))
+ .ToProperty(this, x => x.CombinedContent);
- public ObservableCollection<TagViewModel> Tags
- {
- get => _tags;
- set => this.RaiseAndSetIfChanged(ref _tags, value);
+ // This is here just to activate/initialize the above rxui stuff.
+ Tags.Clear();
}
- public TagInputViewModel TagInput
+ private IEnumerable _suggestions;
+
+ public IEnumerable Suggestions
{
- get => _tagInput;
- set => this.RaiseAndSetIfChanged(ref _tagInput, value);
+ get => _suggestions;
+ set => this.RaiseAndSetIfChanged(ref _suggestions, value);
}
- private void AddTagHandler(ObservableCollection<TagViewModel> tags)
+
+ public IEnumerable<object> CombinedContent => _combinedContent.Value;
+
+ public ObservableCollection<TagViewModel> Tags
{
- _combinedContent = tags
- .ToObservableChangeSet(x => x)
- .ToCollection()
- .Select(x => x.Count != 0)
- .Merge(this.WhenAnyValue(x => x.Tags).Select(x => x is { }))
- .Merge(this.WhenAnyValue(x => x.TagInput).Select(x => x is { }))
- .Select(x => Tags.Append((object)TagInput))
- .ToProperty(this, x => x.CombinedContent);
+ get => _tags;
+ set => this.RaiseAndSetIfChanged(ref _tags, value);
}
public void AddTag()
@@ -60,8 +57,10 @@ namespace WalletWasabi.Fluent.ViewModels.TagsBox
public void RemoveTag()
{
- if (Tags.Count > 0)
+ 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
@@ -6,18 +6,22 @@ namespace WalletWasabi.Fluent.ViewModels.TagsBox
{
public class TagInputViewModel : ViewModelBase
{
- private readonly TagBoxViewModel _parent;
- private IEnumerable _suggestions;
+ private readonly ObservableAsPropertyHelper<IEnumerable> _suggestions;
- public IEnumerable Suggestions
+ private string _inputText;
+
+ public IEnumerable Suggestions => _suggestions.Value;
+
+ public TagInputViewModel(TagBoxViewModel parent)
{
- get => _suggestions;
- set => this.RaiseAndSetIfChanged(ref _suggestions, value);
+ _suggestions = parent.WhenAnyValue(x => x.Suggestions)
+ .ToProperty(this, x => x.Suggestions);
}
- public TagInputViewModel(TagBoxViewModel parent)
+ public string InputText
{
- _parent = parent;
+ get => _inputText;
+ set => this.RaiseAndSetIfChanged(ref _inputText, value);
}
}
}
\ No newline at end of file

ADD
WalletWasabi.Fluent/Views/TagsBox/TagInputView.xaml
+<UserControl xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:c="clr-namespace:WalletWasabi.Fluent.Views.TagsBox"
+ mc:Ignorable="d"
+ x:Class="WalletWasabi.Fluent.Views.TagsBox.TagInputView">
+ <AutoCompleteBox Text="{Binding InputText, Mode=TwoWay}" Items="{Binding Suggestions}"/>
+</UserControl>
\ No newline at end of file

ADD
WalletWasabi.Fluent/Views/TagsBox/TagInputView.xaml.cs
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace WalletWasabi.Fluent.Views.TagsBox
+{
+ public class TagInputView : UserControl
+ {
+ public TagInputView()
+ {
+ InitializeComponent();
+ }
+
+ private void InitializeComponent()
+ {
+ AvaloniaXamlLoader.Load(this);
+ }
+ }
+}
\ No newline at end of file

tag input box impl