修复TagIpoutBUG

修复TextBox值为Null无法删除问题以及AllowDuplicates为false状态 VM中的Tags为null时的异常状态问题
This commit is contained in:
Coolkeke
2023-12-18 21:03:08 +08:00
parent c5f7b9bf55
commit 1d6f3b10ce
3 changed files with 15 additions and 8 deletions

View File

@@ -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)
{