From df8b3e2f491a47829b5a1d11adefdb1354132b6e Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Fri, 1 Nov 2019 00:21:56 +0800 Subject: [PATCH] fixed #196 --- .../Controls/TabControl/TabControl.cs | 35 +++++++++-- .../Controls/TabControl/TabItem.cs | 63 ++++++++++++++++--- .../Themes/Styles/TabControl.xaml | 20 +++--- 3 files changed, 97 insertions(+), 21 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/TabControl/TabControl.cs b/src/Shared/HandyControl_Shared/Controls/TabControl/TabControl.cs index 1c92fd43..31832e95 100644 --- a/src/Shared/HandyControl_Shared/Controls/TabControl/TabControl.cs +++ b/src/Shared/HandyControl_Shared/Controls/TabControl/TabControl.cs @@ -80,16 +80,43 @@ namespace HandyControl.Controls /// /// 是否显示关闭按钮 /// - public static readonly DependencyProperty ShowCloseButtonProperty = DependencyProperty.Register( - "ShowCloseButton", typeof(bool), typeof(TabControl), new PropertyMetadata(ValueBoxes.FalseBox)); + public static readonly DependencyProperty ShowCloseButtonProperty = DependencyProperty.RegisterAttached( + "ShowCloseButton", typeof(bool), typeof(TabControl), new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.Inherits)); + + public static void SetShowCloseButton(DependencyObject element, bool value) + => element.SetValue(ShowCloseButtonProperty, value); + + public static bool GetShowCloseButton(DependencyObject element) + => (bool) element.GetValue(ShowCloseButtonProperty); /// /// 是否显示关闭按钮 /// public bool ShowCloseButton { - get => (bool)GetValue(ShowCloseButtonProperty); - set => SetValue(ShowCloseButtonProperty, value); + get => GetShowCloseButton(this); + set => SetShowCloseButton(this, value); + } + + /// + /// 是否显示上下文菜单 + /// + public static readonly DependencyProperty ShowContextMenuProperty = DependencyProperty.RegisterAttached( + "ShowContextMenu", typeof(bool), typeof(TabControl), new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.Inherits)); + + public static void SetShowContextMenu(DependencyObject element, bool value) + => element.SetValue(ShowContextMenuProperty, value); + + public static bool GetShowContextMenu(DependencyObject element) + => (bool) element.GetValue(ShowContextMenuProperty); + + /// + /// 是否显示上下文菜单 + /// + public bool ShowContextMenu + { + get => GetShowContextMenu(this); + set => SetShowContextMenu(this, value); } /// diff --git a/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs b/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs index c01843d3..2e75b896 100644 --- a/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs +++ b/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs @@ -112,6 +112,57 @@ namespace HandyControl.Controls } } + /// + /// 是否显示关闭按钮 + /// + public static readonly DependencyProperty ShowCloseButtonProperty = + TabControl.ShowCloseButtonProperty.AddOwner(typeof(TabItem)); + + /// + /// 是否显示关闭按钮 + /// + public bool ShowCloseButton + { + get => (bool)GetValue(ShowCloseButtonProperty); + set => SetValue(ShowCloseButtonProperty, value); + } + + public static void SetShowCloseButton(DependencyObject element, bool value) + => element.SetValue(ShowCloseButtonProperty, value); + + public static bool GetShowCloseButton(DependencyObject element) + => (bool)element.GetValue(ShowCloseButtonProperty); + + /// + /// 是否显示上下文菜单 + /// + public static readonly DependencyProperty ShowContextMenuProperty = + TabControl.ShowContextMenuProperty.AddOwner(typeof(TabItem)); + + /// + /// 是否显示上下文菜单 + /// + public bool ShowContextMenu + { + get => (bool) GetValue(ShowContextMenuProperty); + set => SetValue(ShowContextMenuProperty, value); + } + + public static void SetShowContextMenu(DependencyObject element, bool value) + => element.SetValue(ShowContextMenuProperty, value); + + public static bool GetShowContextMenu(DependencyObject element) + => (bool)element.GetValue(ShowContextMenuProperty); + + public static readonly DependencyProperty MenuProperty = DependencyProperty.Register( + "Menu", typeof(ContextMenu), typeof(TabItem), new PropertyMetadata(default(ContextMenu))); + + public ContextMenu Menu + { + get => (ContextMenu) GetValue(MenuProperty); + set => SetValue(MenuProperty, value); + } + /// /// 更新选项卡横向偏移 /// @@ -152,14 +203,10 @@ namespace HandyControl.Controls RaiseEvent(argsClosing); if (argsClosing.Cancel) return; - if (TabControlParent.IsEnableAnimation) - { - TabPanel.SetCurrentValue(TabPanel.FluidMoveDurationProperty, new Duration(TimeSpan.FromMilliseconds(200))); - } - else - { - TabPanel.FluidMoveDuration = new Duration(TimeSpan.FromSeconds(0)); - } + TabPanel.SetCurrentValue(TabPanel.FluidMoveDurationProperty, + TabControlParent.IsEnableAnimation + ? new Duration(TimeSpan.FromMilliseconds(200)) + : new Duration(TimeSpan.FromMilliseconds(1))); TabControlParent.IsInternalAction = true; RaiseEvent(new RoutedEventArgs(ClosedEvent, this)); TabControlParent.Items.Remove(this); diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml index dc715ab0..92ddbcd8 100644 --- a/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml +++ b/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml @@ -23,6 +23,15 @@ + + + + + + + + + @@ -33,18 +42,11 @@ - + - - - - - - - @@ -56,7 +58,7 @@ -