修复TagIpoutBUG
修复TextBox值为Null无法删除问题以及AllowDuplicates为false状态 VM中的Tags为null时的异常状态问题
This commit is contained in:
@@ -12,7 +12,9 @@
|
||||
<u:TagInput
|
||||
Name="labels"
|
||||
Margin="20"
|
||||
Separator="-" />
|
||||
AllowDuplicates="False"
|
||||
Separator="-"
|
||||
Tags="{Binding Tags}" />
|
||||
<u:TagInput
|
||||
Margin="20"
|
||||
AllowDuplicates="False"
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public class TagInputDemoViewModel: ViewModelBase
|
||||
{
|
||||
|
||||
private ObservableCollection<string> _Tags ;
|
||||
public ObservableCollection<string> Tags
|
||||
{
|
||||
get { return _Tags; }
|
||||
set { SetProperty(ref _Tags, value); }
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user