diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml
index de559222..d1744bb2 100644
--- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml
@@ -16,18 +16,30 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs
index bd6f4e75..91f12591 100644
--- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs
+++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs
@@ -1,13 +1,50 @@
-using HandyControlDemo.Data;
+using System;
+using System.Collections.ObjectModel;
+using GalaSoft.MvvmLight;
+using GalaSoft.MvvmLight.Command;
+using HandyControl.Controls;
+using HandyControlDemo.Data;
+using HandyControlDemo.Properties.Langs;
using HandyControlDemo.Service;
namespace HandyControlDemo.ViewModel
{
- public class TagDemoViewModel : DemoViewModelBase
+ public class TagDemoViewModel : ViewModelBase
{
public TagDemoViewModel(DataService dataService)
{
- DataList = dataService.GetDemoDataList(10);
+ DataList = new ObservableCollection(dataService.GetDemoDataList(10));
}
+
+ public ObservableCollection DataList { get; set; }
+
+ private string _tagName;
+
+ public string TagName
+ {
+ get => _tagName;
+#if NET40
+ set => Set(nameof(TagName), ref _tagName, value);
+#else
+ set => Set(ref _tagName, value);
+#endif
+ }
+
+ public RelayCommand AddItemCmd => new Lazy(() =>
+ new RelayCommand(() =>
+ {
+ if (string.IsNullOrEmpty(TagName))
+ {
+ Growl.Warning(Lang.PlsEnterContent);
+ return;
+ }
+
+ DataList.Insert(0, new DemoDataModel
+ {
+ IsSelected = DataList.Count % 2 == 0,
+ Name = TagName
+ });
+ TagName = string.Empty;
+ })).Value;
}
}
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/ViewModelLocator.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/ViewModelLocator.cs
index 271bf4cc..834f34e9 100644
--- a/src/Shared/HandyControlDemo_Shared/ViewModel/ViewModelLocator.cs
+++ b/src/Shared/HandyControlDemo_Shared/ViewModel/ViewModelLocator.cs
@@ -98,7 +98,7 @@ namespace HandyControlDemo.ViewModel
public SplitButtonDemoViewModel SplitButtonDemo => SimpleIoc.Default.GetInstance();
- public TagDemoViewModel TagDemo => SimpleIoc.Default.GetInstance();
+ public TagDemoViewModel TagDemo => new TagDemoViewModel(SimpleIoc.Default.GetInstance());
#endregion
}
diff --git a/src/Shared/HandyControl_Shared/Controls/Tag/TagContainer.cs b/src/Shared/HandyControl_Shared/Controls/Tag/TagContainer.cs
index d569bee4..f79d1488 100644
--- a/src/Shared/HandyControl_Shared/Controls/Tag/TagContainer.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Tag/TagContainer.cs
@@ -1,10 +1,51 @@
-using System.Windows;
+using System.Collections;
+using System.Windows;
using System.Windows.Controls;
+using HandyControl.Tools.Extension;
namespace HandyControl.Controls
{
public class TagContainer : ItemsControl
{
+ public TagContainer()
+ {
+ AddHandler(Controls.Tag.ClosedEvent, new RoutedEventHandler(Tag_OnClosed));
+ }
+
+ private void Tag_OnClosed(object sender, RoutedEventArgs e)
+ {
+ if (e.OriginalSource is Tag tag)
+ {
+ tag.Hide();
+
+ if (ItemsSource == null)
+ {
+ Items.Remove(tag);
+ }
+ else
+ {
+ var item = ItemContainerGenerator.ItemFromContainer(tag);
+ GetActualList()?.Remove(item);
+ Items.Refresh();
+ }
+ }
+ }
+
+ internal IList GetActualList()
+ {
+ IList list;
+ if (ItemsSource != null)
+ {
+ list = ItemsSource as IList;
+ }
+ else
+ {
+ list = Items;
+ }
+
+ return list;
+ }
+
protected override DependencyObject GetContainerForItemOverride() => new Tag();
protected override bool IsItemItsOwnContainerOverride(object item) => item is Tag;
diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/TagBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/TagBaseStyle.xaml
index e756f371..c87462f9 100644
--- a/src/Shared/HandyControl_Shared/Themes/Styles/Base/TagBaseStyle.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/TagBaseStyle.xaml
@@ -7,6 +7,7 @@
+
@@ -21,6 +22,7 @@
+