diff --git a/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj b/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj index 7757b408..558fd8bb 100644 --- a/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj +++ b/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj @@ -876,6 +876,9 @@ ViewModel\TabControlDemoViewModel.cs + + ViewModel\TagDemoViewModel.cs + ViewModel\WindowDemoViewModel.cs diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems index 89e561b3..d1ba9d54 100644 --- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems +++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems @@ -419,6 +419,7 @@ + diff --git a/src/Shared/HandyControlDemo_Shared/Service/Data/DataService.cs b/src/Shared/HandyControlDemo_Shared/Service/Data/DataService.cs index 76c84413..3df40270 100644 --- a/src/Shared/HandyControlDemo_Shared/Service/Data/DataService.cs +++ b/src/Shared/HandyControlDemo_Shared/Service/Data/DataService.cs @@ -80,7 +80,7 @@ namespace HandyControlDemo.Service return list; } - public List GetDemoDataList(int count) + internal List GetDemoDataList(int count) { var list = new List(); for (var i = 1; i <= count; i++) diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml index 7926ed2d..de559222 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml @@ -4,19 +4,30 @@ Background="{DynamicResource RegionBrush}" xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs" xmlns:ex="clr-namespace:HandyControlDemo.Tools.Extension" - xmlns:hc="https://handyorg.github.io/handycontrol"> + xmlns:hc="https://handyorg.github.io/handycontrol" + DataContext="{Binding TagDemo,Source={StaticResource Locator}}"> + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml.cs index 60662402..aaeb7890 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml.cs +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TagDemoCtl.xaml.cs @@ -1,8 +1,4 @@ -using System; -using HandyControl.Controls; -using HandyControlDemo.Properties.Langs; - -namespace HandyControlDemo.UserControl +namespace HandyControlDemo.UserControl { public partial class TagDemoCtl { @@ -10,15 +6,5 @@ namespace HandyControlDemo.UserControl { InitializeComponent(); } - - //private void TagPanel_OnAddTagButtonClick(object sender, EventArgs e) - //{ - // if (sender is TagPanel panel) - // { - // var tag = new Tag(); - // LangProvider.SetLang(tag, ContentProperty, LangKeys.SubTitle); - // panel.Children.Add(tag); - // } - //} } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs new file mode 100644 index 00000000..bd6f4e75 --- /dev/null +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs @@ -0,0 +1,13 @@ +using HandyControlDemo.Data; +using HandyControlDemo.Service; + +namespace HandyControlDemo.ViewModel +{ + public class TagDemoViewModel : DemoViewModelBase + { + public TagDemoViewModel(DataService dataService) + { + DataList = dataService.GetDemoDataList(10); + } + } +} \ 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 6c1ba828..271bf4cc 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/ViewModelLocator.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/ViewModelLocator.cs @@ -38,6 +38,7 @@ namespace HandyControlDemo.ViewModel SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); } public static ViewModelLocator Instance => new Lazy(() => @@ -97,6 +98,8 @@ namespace HandyControlDemo.ViewModel public SplitButtonDemoViewModel SplitButtonDemo => SimpleIoc.Default.GetInstance(); + public TagDemoViewModel TagDemo => SimpleIoc.Default.GetInstance(); + #endregion } } \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Controls/Tag/Tag.cs b/src/Shared/HandyControl_Shared/Controls/Tag/Tag.cs index f8dec4e3..6e175a63 100644 --- a/src/Shared/HandyControl_Shared/Controls/Tag/Tag.cs +++ b/src/Shared/HandyControl_Shared/Controls/Tag/Tag.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -52,6 +53,64 @@ namespace HandyControl.Controls set => SetValue(IsSelectedProperty, ValueBoxes.BooleanBox(value)); } + public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register( + "Header", typeof(object), typeof(Tag), new PropertyMetadata(default, OnHeaderChanged)); + + private static void OnHeaderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var ctrl = (Tag)d; + + ctrl.SetValue(HasHeaderPropertyKey, e.NewValue != null ? ValueBoxes.TrueBox : ValueBoxes.FalseBox); + ctrl.OnHeaderChanged(e.OldValue, e.NewValue); + } + + protected virtual void OnHeaderChanged(object oldHeader, object newHeader) + { + RemoveLogicalChild(oldHeader); + AddLogicalChild(newHeader); + } + + public object Header + { + get => GetValue(HeaderProperty); + set => SetValue(HeaderProperty, value); + } + + internal static readonly DependencyPropertyKey HasHeaderPropertyKey = DependencyProperty.RegisterReadOnly( + "HasHeader", typeof(bool), typeof(Tag), new PropertyMetadata(ValueBoxes.FalseBox)); + + public static readonly DependencyProperty HasHeaderProperty = HasHeaderPropertyKey.DependencyProperty; + + [Bindable(false), Browsable(false)] + public bool HasHeader => (bool) GetValue(HasHeaderProperty); + + public static readonly DependencyProperty HeaderStringFormatProperty = DependencyProperty.Register( + "HeaderStringFormat", typeof(string), typeof(Tag), new PropertyMetadata(default(string))); + + public string HeaderStringFormat + { + get => (string) GetValue(HeaderStringFormatProperty); + set => SetValue(HeaderStringFormatProperty, value); + } + + public static readonly DependencyProperty HeaderTemplateSelectorProperty = DependencyProperty.Register( + "HeaderTemplateSelector", typeof(DataTemplateSelector), typeof(Tag), new PropertyMetadata(default(DataTemplateSelector))); + + public DataTemplateSelector HeaderTemplateSelector + { + get => (DataTemplateSelector) GetValue(HeaderTemplateSelectorProperty); + set => SetValue(HeaderTemplateSelectorProperty, value); + } + + public static readonly DependencyProperty HeaderTemplateProperty = DependencyProperty.Register( + "HeaderTemplate", typeof(DataTemplate), typeof(Tag), new PropertyMetadata(default(DataTemplate))); + + public DataTemplate HeaderTemplate + { + get => (DataTemplate) GetValue(HeaderTemplateProperty); + set => SetValue(HeaderTemplateProperty, value); + } + public static readonly RoutedEvent SelectedEvent = EventManager.RegisterRoutedEvent("Selected", RoutingStrategy.Bubble, typeof(EventHandler), typeof(Tag)); public event EventHandler Selected diff --git a/src/Shared/HandyControl_Shared/Controls/Tag/TagContainer.cs b/src/Shared/HandyControl_Shared/Controls/Tag/TagContainer.cs index 2d1ea37b..d569bee4 100644 --- a/src/Shared/HandyControl_Shared/Controls/Tag/TagContainer.cs +++ b/src/Shared/HandyControl_Shared/Controls/Tag/TagContainer.cs @@ -1,20 +1,10 @@ using System.Windows; using System.Windows.Controls; -using HandyControl.Data; namespace HandyControl.Controls { public class TagContainer : ItemsControl { - public static readonly DependencyProperty IsToolBarVisibleProperty = DependencyProperty.Register( - "IsToolBarVisible", typeof(bool), typeof(TagContainer), new PropertyMetadata(ValueBoxes.FalseBox)); - - public bool IsToolBarVisible - { - get => (bool) GetValue(IsToolBarVisibleProperty); - set => SetValue(IsToolBarVisibleProperty, value); - } - protected override DependencyObject GetContainerForItemOverride() => new Tag(); protected override bool IsItemItsOwnContainerOverride(object item) => item is Tag; diff --git a/src/Shared/HandyControl_Shared/Controls/Tag/TagPanel.cs b/src/Shared/HandyControl_Shared/Controls/Tag/TagPanel.cs deleted file mode 100644 index dd0ac447..00000000 --- a/src/Shared/HandyControl_Shared/Controls/Tag/TagPanel.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Media.Animation; -using HandyControl.Data; -using HandyControl.Interactivity; -using HandyControl.Tools; - -namespace HandyControl.Controls -{ - public class TagPanel : WrapPanel - { - private Button _addTagButton; - - private bool _isInternalAction; - - public TagPanel() - { - var behavior = new FluidMoveBehavior - { - AppliesTo = FluidMoveScope.Children, - Duration = new Duration(TimeSpan.FromMilliseconds(200)), - EaseY = new PowerEase(), - EaseX = new PowerEase() - }; - var collection = Interaction.GetBehaviors(this); - collection.Add(behavior); - - AddHandler(Controls.Tag.ClosedEvent, new RoutedEventHandler(Tag_OnClosed)); - } - - private void Tag_OnClosed(object sender, RoutedEventArgs e) => Children.Remove(e.OriginalSource as Tag); - - public static readonly RoutedEvent AddTagButtonClickEvent = EventManager.RegisterRoutedEvent("AddTagButtonClick", RoutingStrategy.Bubble, typeof(EventHandler), typeof(TagPanel)); - - public event EventHandler AddTagButtonClick - { - add => AddHandler(AddTagButtonClickEvent, value); - remove => RemoveHandler(AddTagButtonClickEvent, value); - } - - public static readonly DependencyProperty ShowAddButtonProperty = DependencyProperty.Register( - "ShowAddButton", typeof(bool), typeof(TagPanel), new PropertyMetadata(ValueBoxes.FalseBox)); - - public bool ShowAddButton - { - get => (bool) GetValue(ShowAddButtonProperty); - set => SetValue(ShowAddButtonProperty, ValueBoxes.BooleanBox(value)); - } - - public static readonly DependencyProperty TagMarginProperty = DependencyProperty.Register( - "TagMargin", typeof(Thickness), typeof(TagPanel), new PropertyMetadata(new Thickness(5))); - - public Thickness TagMargin - { - get => (Thickness) GetValue(TagMarginProperty); - set => SetValue(TagMarginProperty, value); - } - - protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved) - { - if (!(visualAdded is Tag tag)) return; - base.OnVisualChildrenChanged(visualAdded, visualRemoved); - - tag.Margin = TagMargin; - if (_isInternalAction) return; - if (ShowAddButton) - { - _isInternalAction = true; - if (!Children.Contains(_addTagButton)) - { - _addTagButton = new Button - { - Style = ResourceHelper.GetResource - - \ No newline at end of file