From 4cd13e84b25ac6ae693bb9f2a1dbbbb4e6cda828 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Tue, 11 Sep 2018 15:17:51 +0800 Subject: [PATCH] Fixed a bug of tabcontrol --- HandyControl/Controls/TabControl/TabControl.cs | 7 ++++--- HandyControl/Controls/TabControl/TabPanel.cs | 8 +++++--- HandyControl/Themes/Styles/TabControl.xaml | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/HandyControl/Controls/TabControl/TabControl.cs b/HandyControl/Controls/TabControl/TabControl.cs index 38e24b2f..99e79d94 100644 --- a/HandyControl/Controls/TabControl/TabControl.cs +++ b/HandyControl/Controls/TabControl/TabControl.cs @@ -133,7 +133,7 @@ namespace HandyControl.Controls if (!IsEnableTabFill) { _itemShowCount = (int)(ActualWidth / TabItemWidth); - _buttonOverflow.Show(Items.Count >= _itemShowCount); + _buttonOverflow.Show(Items.Count > 0 && Items.Count >= _itemShowCount); } if (IsInternalAction) @@ -151,9 +151,10 @@ namespace HandyControl.Controls } if (e.Action == NotifyCollectionChangedAction.Add) { - foreach (UIElement item in e.NewItems) + foreach (TabItem item in e.NewItems) { item.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); + item.IsSelected = true; } } IsInternalAction = false; @@ -170,7 +171,7 @@ namespace HandyControl.Controls if (_buttonOverflow != null) { _itemShowCount = (int)(ActualWidth / TabItemWidth); - _buttonOverflow.Show(Items.Count >= _itemShowCount); + _buttonOverflow.Show(Items.Count > 0 && Items.Count >= _itemShowCount); var menu = new ContextMenu { diff --git a/HandyControl/Controls/TabControl/TabPanel.cs b/HandyControl/Controls/TabControl/TabPanel.cs index 7c7de2a7..39fd164b 100644 --- a/HandyControl/Controls/TabControl/TabPanel.cs +++ b/HandyControl/Controls/TabControl/TabPanel.cs @@ -107,7 +107,7 @@ namespace HandyControl.Controls var count = InternalChildren.Count; if (count == 0) { - _oldSize.Width = 0; + _oldSize = new Size(); return _oldSize; } constraint.Width += InternalChildren.Count; @@ -121,7 +121,10 @@ namespace HandyControl.Controls } else { - arr = ArithmeticHelper.DivideInt2Arr((int)constraint.Width, count); + if (TemplatedParent is TabControl tabControl) + { + arr = ArithmeticHelper.DivideInt2Arr((int)tabControl.ActualWidth + InternalChildren.Count, count); + } } for (var index = 0; index < count; index++) @@ -140,7 +143,6 @@ namespace HandyControl.Controls Width = itemWidth, Height = TabItemHeight }; - Console.WriteLine(rect); tabItem.Arrange(rect); tabItem.ItemWidth = itemWidth - tabItem.BorderThickness.Left; tabItem.CurrentIndex = index; diff --git a/HandyControl/Themes/Styles/TabControl.xaml b/HandyControl/Themes/Styles/TabControl.xaml index 925d6ae4..a6de7dd9 100644 --- a/HandyControl/Themes/Styles/TabControl.xaml +++ b/HandyControl/Themes/Styles/TabControl.xaml @@ -81,7 +81,7 @@ - +