diff --git a/demo/Ursa.Demo/Pages/TagInputDemo.axaml b/demo/Ursa.Demo/Pages/TagInputDemo.axaml
index d73fcb3..d5751e5 100644
--- a/demo/Ursa.Demo/Pages/TagInputDemo.axaml
+++ b/demo/Ursa.Demo/Pages/TagInputDemo.axaml
@@ -9,7 +9,14 @@
d:DesignWidth="800"
mc:Ignorable="d">
-
+
+
diff --git a/src/Ursa.Themes.Semi/Controls/TagInput.axaml b/src/Ursa.Themes.Semi/Controls/TagInput.axaml
index 4443f32..47cf6c6 100644
--- a/src/Ursa.Themes.Semi/Controls/TagInput.axaml
+++ b/src/Ursa.Themes.Semi/Controls/TagInput.axaml
@@ -6,6 +6,7 @@
+
@@ -15,9 +16,10 @@
-
-
+
+
@@ -84,14 +86,15 @@
-
+
@@ -99,6 +102,7 @@
Name="{x:Static u:ClosableTag.PART_CloseButton}"
Width="8"
Height="8"
+ Margin="4,0"
Background="Transparent"
Data="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"
DockPanel.Dock="Right" />
diff --git a/src/Ursa/Controls/TagInput/TagInput.cs b/src/Ursa/Controls/TagInput/TagInput.cs
index 38d54a5..ad568a9 100644
--- a/src/Ursa/Controls/TagInput/TagInput.cs
+++ b/src/Ursa/Controls/TagInput/TagInput.cs
@@ -65,6 +65,24 @@ public class TagInput: TemplatedControl
set => SetValue(ItemTemplateProperty, value);
}
+ public static readonly StyledProperty SeparatorProperty = AvaloniaProperty.Register(
+ nameof(Separator));
+
+ public string Separator
+ {
+ get => GetValue(SeparatorProperty);
+ set => SetValue(SeparatorProperty, value);
+ }
+
+ public static readonly StyledProperty AllowDuplicatesProperty = AvaloniaProperty.Register(
+ nameof(AllowDuplicates), defaultValue: true);
+
+ public bool AllowDuplicates
+ {
+ get => GetValue(AllowDuplicatesProperty);
+ set => SetValue(AllowDuplicatesProperty, value);
+ }
+
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
@@ -82,8 +100,26 @@ public class TagInput: TemplatedControl
{
if (_textBox.Text?.Length > 0)
{
- Items.Insert(Items.Count - 1, _textBox.Text);
- Tags.Insert(Items.Count - 2, _textBox.Text ?? string.Empty);
+ string[] values;
+ if (!string.IsNullOrEmpty(Separator))
+ {
+ values = _textBox.Text.Split(new string[] { Separator },
+ StringSplitOptions.RemoveEmptyEntries);
+ }
+ else
+ {
+ values = new[] { _textBox.Text };
+ }
+
+ if (!AllowDuplicates)
+ {
+ values = values.Distinct().Except(Tags).ToArray();
+ }
+ for(int i = 0; i < values.Length; i++)
+ {
+ Items.Insert(Items.Count - 1, values[i]);
+ Tags.Insert(Items.Count - 2, values[i]);
+ }
_textBox.Text = "";
}
}
@@ -91,6 +127,10 @@ public class TagInput: TemplatedControl
{
if (_textBox.Text?.Length == 0)
{
+ if (Tags.Count == 0)
+ {
+ return;
+ }
Items.RemoveAt(Items.Count - 2);
Tags.RemoveAt(Items.Count - 1);
}
diff --git a/src/Ursa/Controls/TagInput/TagInputPanel.cs b/src/Ursa/Controls/TagInput/TagInputPanel.cs
index 9efd6d4..38117e4 100644
--- a/src/Ursa/Controls/TagInput/TagInputPanel.cs
+++ b/src/Ursa/Controls/TagInput/TagInputPanel.cs
@@ -71,7 +71,7 @@ public class TagInputPanel: Panel
// Width is enough to place next child
if (MathUtilities.GreaterThan(deltaX, child.DesiredSize.Width))
{
- child.Arrange(new Rect(currentLineX, totalHeight, child.DesiredSize.Width, child.DesiredSize.Height));
+ child.Arrange(new Rect(currentLineX, totalHeight, child.DesiredSize.Width, Math.Max(child.DesiredSize.Height, currentLineHeight)));
currentLineX += child.DesiredSize.Width;
currentLineHeight = Math.Max(currentLineHeight, child.DesiredSize.Height);
}
@@ -99,7 +99,9 @@ public class TagInputPanel: Panel
}
else
{
- last.Arrange(new Rect(currentLineX, totalHeight,lastDeltaX, last.DesiredSize.Height));
+ currentLineHeight = children.Count == 1 ? finalSize.Height : currentLineHeight;
+ last.Arrange(new Rect(currentLineX, totalHeight, lastDeltaX,
+ Math.Max(currentLineHeight, last.DesiredSize.Height)));
currentLineHeight = Math.Max(currentLineHeight, last.DesiredSize.Height);
totalHeight += currentLineHeight;
}