diff --git a/demo/Ursa.Demo/Pages/TagInputDemo.axaml b/demo/Ursa.Demo/Pages/TagInputDemo.axaml
index 8a4f839..822f316 100644
--- a/demo/Ursa.Demo/Pages/TagInputDemo.axaml
+++ b/demo/Ursa.Demo/Pages/TagInputDemo.axaml
@@ -12,7 +12,9 @@
+ AllowDuplicates="False"
+ Separator="-"
+ Tags="{Binding Tags}" />
_Tags ;
+ public ObservableCollection Tags
+ {
+ get { return _Tags; }
+ set { SetProperty(ref _Tags, value); }
+ }
}
\ No newline at end of file
diff --git a/src/Ursa/Controls/TagInput/TagInput.cs b/src/Ursa/Controls/TagInput/TagInput.cs
index 488fe3d..f57e7eb 100644
--- a/src/Ursa/Controls/TagInput/TagInput.cs
+++ b/src/Ursa/Controls/TagInput/TagInput.cs
@@ -210,24 +210,22 @@ public class TagInput : TemplatedControl
values = new[] { _textBox.Text };
}
- if (!AllowDuplicates)
- {
+ if (!AllowDuplicates && Tags != null)
values = values.Distinct().Except(Tags).ToArray();
- }
for (int i = 0; i < values.Length; i++)
{
int index = Items.Count - 1;
// Items.Insert(index, values[i]);
- Tags.Insert(index, values[i]);
+ Tags?.Insert(index, values[i]);
}
_textBox.Text = "";
}
}
else if (args.Key == Key.Delete || args.Key == Key.Back)
- {
- if (_textBox.Text?.Length == 0)
+ {
+ if (string.IsNullOrEmpty(_textBox.Text)||_textBox.Text?.Length == 0)
{
if (Tags.Count == 0)
{