diff --git a/src/Ursa.Themes.Semi/Controls/TagInput.axaml b/src/Ursa.Themes.Semi/Controls/TagInput.axaml index 7a43ce9..6829870 100644 --- a/src/Ursa.Themes.Semi/Controls/TagInput.axaml +++ b/src/Ursa.Themes.Semi/Controls/TagInput.axaml @@ -6,7 +6,7 @@ - + @@ -16,10 +16,13 @@ + + @@ -48,6 +57,7 @@ + @@ -87,15 +97,19 @@ + + + + + Data="{DynamicResource ClosableTagCloseIconGlyph}" + DockPanel.Dock="Right" + Foreground="{TemplateBinding Foreground}" /> diff --git a/src/Ursa.Themes.Semi/Themes/Dark/TagInput.axaml b/src/Ursa.Themes.Semi/Themes/Dark/TagInput.axaml new file mode 100644 index 0000000..c32a707 --- /dev/null +++ b/src/Ursa.Themes.Semi/Themes/Dark/TagInput.axaml @@ -0,0 +1,4 @@ + + + + diff --git a/src/Ursa.Themes.Semi/Themes/Dark/_index.axaml b/src/Ursa.Themes.Semi/Themes/Dark/_index.axaml index c892d42..c9f2bea 100644 --- a/src/Ursa.Themes.Semi/Themes/Dark/_index.axaml +++ b/src/Ursa.Themes.Semi/Themes/Dark/_index.axaml @@ -9,6 +9,7 @@ + diff --git a/src/Ursa.Themes.Semi/Themes/Light/TagInput.axaml b/src/Ursa.Themes.Semi/Themes/Light/TagInput.axaml new file mode 100644 index 0000000..c3b76e1 --- /dev/null +++ b/src/Ursa.Themes.Semi/Themes/Light/TagInput.axaml @@ -0,0 +1,4 @@ + + + + diff --git a/src/Ursa.Themes.Semi/Themes/Light/_index.axaml b/src/Ursa.Themes.Semi/Themes/Light/_index.axaml index c892d42..c9f2bea 100644 --- a/src/Ursa.Themes.Semi/Themes/Light/_index.axaml +++ b/src/Ursa.Themes.Semi/Themes/Light/_index.axaml @@ -9,6 +9,7 @@ + diff --git a/src/Ursa.Themes.Semi/Themes/Shared/TagInput.axaml b/src/Ursa.Themes.Semi/Themes/Shared/TagInput.axaml new file mode 100644 index 0000000..2f3d2b7 --- /dev/null +++ b/src/Ursa.Themes.Semi/Themes/Shared/TagInput.axaml @@ -0,0 +1,5 @@ + + + M17.6568 19.7782C18.2426 20.3639 19.1924 20.3639 19.7782 19.7782C20.3639 19.1924 20.3639 18.2426 19.7782 17.6568L14.1213 12L19.7782 6.34313C20.3639 5.75734 20.3639 4.8076 19.7782 4.22181C19.1924 3.63602 18.2426 3.63602 17.6568 4.22181L12 9.87866L6.34313 4.22181C5.75734 3.63602 4.8076 3.63602 4.22181 4.22181C3.63602 4.8076 3.63602 5.75734 4.22181 6.34313L9.87866 12L4.22181 17.6568C3.63602 18.2426 3.63602 19.1924 4.22181 19.7782C4.8076 20.3639 5.75734 20.3639 6.34313 19.7782L12 14.1213L17.6568 19.7782Z + 32 + diff --git a/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml b/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml index 5e6a238..777a0a4 100644 --- a/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml +++ b/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml @@ -8,5 +8,6 @@ + diff --git a/src/Ursa/Controls/TagInput/TagInput.cs b/src/Ursa/Controls/TagInput/TagInput.cs index 32a3e64..5ee089b 100644 --- a/src/Ursa/Controls/TagInput/TagInput.cs +++ b/src/Ursa/Controls/TagInput/TagInput.cs @@ -14,26 +14,31 @@ using Avalonia.Styling; namespace Ursa.Controls; -[TemplatePart (PART_ItemsControl, typeof (ItemsControl))] -public class TagInput: TemplatedControl +[TemplatePart(PART_ItemsControl, typeof(ItemsControl))] +public class TagInput : TemplatedControl { public const string PART_ItemsControl = "PART_ItemsControl"; - + private readonly TextBox _textBox; private ItemsControl? _itemsControl; - - - public static readonly StyledProperty> TagsProperty = AvaloniaProperty.Register>( - nameof(Tags)); + + + public static readonly StyledProperty> TagsProperty = + AvaloniaProperty.Register>( + nameof(Tags)); + public IList Tags { get => GetValue(TagsProperty); set => SetValue(TagsProperty, value); } - - public static readonly DirectProperty ItemsProperty = AvaloniaProperty.RegisterDirect( - nameof(Items), o => o.Items); + + public static readonly DirectProperty ItemsProperty = + AvaloniaProperty.RegisterDirect( + nameof(Items), o => o.Items); + private IList _items; + public IList Items { get => _items; @@ -48,8 +53,9 @@ public class TagInput: TemplatedControl Tags = new ObservableCollection(); } - public static readonly StyledProperty InputThemeProperty = AvaloniaProperty.Register( - nameof(InputTheme)); + public static readonly StyledProperty InputThemeProperty = + AvaloniaProperty.Register( + nameof(InputTheme)); public ControlTheme InputTheme { @@ -57,8 +63,9 @@ public class TagInput: TemplatedControl set => SetValue(InputThemeProperty, value); } - public static readonly StyledProperty ItemTemplateProperty = AvaloniaProperty.Register( - nameof(ItemTemplate)); + public static readonly StyledProperty ItemTemplateProperty = + AvaloniaProperty.Register( + nameof(ItemTemplate)); public IDataTemplate? ItemTemplate { @@ -84,6 +91,27 @@ public class TagInput: TemplatedControl set => SetValue(AllowDuplicatesProperty, value); } + public static readonly StyledProperty InnerLeftContentProperty = + AvaloniaProperty.Register( + nameof(InnerLeftContent)); + + public object? InnerLeftContent + { + get => GetValue(InnerLeftContentProperty); + set => SetValue(InnerLeftContentProperty, value); + } + + public static readonly StyledProperty InnerRightContentProperty = + AvaloniaProperty.Register( + nameof(InnerRightContent)); + + public object? InnerRightContent + { + get => GetValue(InnerRightContentProperty); + set => SetValue(InnerRightContentProperty, value); + } + + static TagInput() { InputThemeProperty.Changed.AddClassHandler((o, e) => o.OnInputThemePropertyChanged(e)); @@ -93,7 +121,7 @@ public class TagInput: TemplatedControl protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); - _itemsControl = e.NameScope.Find(PART_ItemsControl); + _itemsControl = e.NameScope.Find(PART_ItemsControl); Items.Add(_textBox); } @@ -105,14 +133,15 @@ public class TagInput: TemplatedControl _textBox.Theme = newTheme; } } - + private void OnTagsPropertyChanged(AvaloniaPropertyChangedEventArgs args) { var newTags = args.GetNewValue>(); for (int i = 0; i < Items.Count - 1; i++) { - Items.RemoveAt(Items.Count-1); + Items.RemoveAt(Items.Count - 1); } + for (int i = 0; i < newTags.Count; i++) { Items.Insert(Items.Count - 1, newTags[i]); @@ -140,11 +169,14 @@ public class TagInput: TemplatedControl { values = values.Distinct().Except(Tags).ToArray(); } - for(int i = 0; i < values.Length; i++) + + for (int i = 0; i < values.Length; i++) { - Items.Insert(Items.Count - 1, values[i]); - Tags.Insert(Items.Count - 2, values[i]); + int index = Items.Count - 1; + Items.Insert(index, values[i]); + Tags.Insert(index, values[i]); } + _textBox.Text = ""; } } @@ -156,8 +188,9 @@ public class TagInput: TemplatedControl { return; } - Items.RemoveAt(Items.Count - 2); - Tags.RemoveAt(Items.Count - 1); + int index = Items.Count - 2; + Items.RemoveAt(index); + Tags.RemoveAt(index); } } }