diff --git a/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml b/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml index 67cbd792..69d06ef6 100644 --- a/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml +++ b/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml @@ -11038,7 +11038,7 @@ - + @@ -11048,7 +11048,6 @@ - @@ -11059,7 +11058,6 @@ - @@ -11070,7 +11068,6 @@ - @@ -11277,6 +11274,29 @@ + + @@ -13808,7 +13923,7 @@ - + @@ -13818,7 +13933,6 @@ - @@ -13827,7 +13941,6 @@ - @@ -13840,7 +13953,6 @@ - diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Styles/NativeTabControlDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Styles/NativeTabControlDemoCtl.xaml index add47557..33c2db39 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Styles/NativeTabControlDemoCtl.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Styles/NativeTabControlDemoCtl.xaml @@ -8,42 +8,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + @@ -52,40 +136,40 @@ - - + + - - + + - - + + - - + + - - + + @@ -94,40 +178,40 @@ - - + + - - + + - - + + - - + + - - + + @@ -136,40 +220,40 @@ - - + + - - + + - - + + - - + + - - + + diff --git a/src/Shared/HandyControl_Shared/Controls/TabControl/SlidingTabContainer.cs b/src/Shared/HandyControl_Shared/Controls/TabControl/SlidingTabContainer.cs new file mode 100644 index 00000000..edb75ebd --- /dev/null +++ b/src/Shared/HandyControl_Shared/Controls/TabControl/SlidingTabContainer.cs @@ -0,0 +1,121 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Media.Animation; +using HandyControl.Tools; + +namespace HandyControl.Controls; + +[TemplatePart(Name = ElementSliding, Type = typeof(FrameworkElement))] +public class SlidingTabContainer : ContentControl +{ + private const string ElementSliding = "PART_Sliding"; + + private FrameworkElement _sliding = new(); + private System.Windows.Controls.TabControl _tabControl; + + public SlidingTabContainer() + { + Loaded += OnLoaded; + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + Loaded -= OnLoaded; + OnSelectionChanged(null, null); + } + + public override void OnApplyTemplate() + { + if (_tabControl is not null) + { + _tabControl.SelectionChanged -= OnSelectionChanged; + } + + base.OnApplyTemplate(); + + _tabControl = VisualHelper.GetParent(this); + _sliding = GetTemplateChild(ElementSliding) as FrameworkElement; + + if (_tabControl is not null) + { + _tabControl.SelectionChanged += OnSelectionChanged; + + if (IsLoaded) + { + OnSelectionChanged(null, null); + } + } + } + + protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) + { + base.OnRenderSizeChanged(sizeInfo); + + if (_tabControl is null) + { + return; + } + + OnSelectionChanged(null, null); + } + + private void OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (_sliding is null || !IsLoaded) + { + return; + } + + if (_tabControl.ItemContainerGenerator.ContainerFromItem(_tabControl.SelectedItem) is not System.Windows.Controls.TabItem tabItem) + { + return; + } + + var offset = VisualTreeHelper.GetOffset(tabItem); + var tabWidth = tabItem.ActualWidth; + var tabHeight = tabItem.ActualHeight; + var useAnimation = _sliding.Width > 0 && _sliding.Height > 0; + + if (useAnimation) + { + var storyboard = new Storyboard(); + var easingFuction = new PowerEase + { + EasingMode = EasingMode.EaseOut, + }; + + var widthAnimation = AnimationHelper.CreateAnimation(tabWidth); + widthAnimation.EasingFunction = easingFuction; + Storyboard.SetTarget(widthAnimation, _sliding); + Storyboard.SetTargetProperty(widthAnimation, new PropertyPath(WidthProperty.Name)); + storyboard.Children.Add(widthAnimation); + + var heightAnimation = AnimationHelper.CreateAnimation(tabHeight); + heightAnimation.EasingFunction = easingFuction; + Storyboard.SetTarget(heightAnimation, _sliding); + Storyboard.SetTargetProperty(heightAnimation, new PropertyPath(HeightProperty.Name)); + storyboard.Children.Add(heightAnimation); + + var xAnimation = AnimationHelper.CreateAnimation(offset.X); + xAnimation.EasingFunction = easingFuction; + Storyboard.SetTarget(xAnimation, _sliding); + Storyboard.SetTargetProperty(xAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.X)")); + storyboard.Children.Add(xAnimation); + + var yAnimation = AnimationHelper.CreateAnimation(offset.Y); + yAnimation.EasingFunction = easingFuction; + Storyboard.SetTarget(yAnimation, _sliding); + Storyboard.SetTargetProperty(yAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)")); + storyboard.Children.Add(yAnimation); + + storyboard.Begin(); + } + else + { + _sliding.Width = tabItem.ActualWidth; + _sliding.Height = tabItem.ActualHeight; + _sliding.RenderTransform = new TranslateTransform(offset.X, offset.Y); + } + } +} diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems index bac2ffb4..7a134535 100644 --- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems +++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems @@ -90,6 +90,7 @@ + diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/TabControlBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/TabControlBaseStyle.xaml index 7bfd7433..92d6eb87 100644 --- a/src/Shared/HandyControl_Shared/Themes/Styles/Base/TabControlBaseStyle.xaml +++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/TabControlBaseStyle.xaml @@ -1,69 +1,64 @@ - + - - - + + + + + diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml index eca88d60..d29a6a75 100644 --- a/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml +++ b/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml @@ -1,68 +1,34 @@ - + - - - - + + + + + + - diff --git a/src/Shared/HandyControl_Shared/Themes/Theme.xaml b/src/Shared/HandyControl_Shared/Themes/Theme.xaml index 9893456d..69654c4f 100644 --- a/src/Shared/HandyControl_Shared/Themes/Theme.xaml +++ b/src/Shared/HandyControl_Shared/Themes/Theme.xaml @@ -11155,7 +11155,7 @@ - + @@ -11165,7 +11165,6 @@ - @@ -11176,7 +11175,6 @@ - @@ -11187,7 +11185,6 @@ - @@ -11394,6 +11391,29 @@ + + @@ -13956,7 +14071,7 @@ - + @@ -13966,7 +14081,6 @@ - @@ -13975,7 +14089,6 @@ - @@ -13988,7 +14101,6 @@ -