diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
index 7a9d0ef9..089614fe 100644
--- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
+++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
@@ -292,6 +292,7 @@
+
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TabControlDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TabControlDemoCtl.xaml
index 94e05c27..2b293612 100644
--- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TabControlDemoCtl.xaml
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/TabControlDemoCtl.xaml
@@ -2,12 +2,22 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="{DynamicResource RegionBrush}"
- xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl">
+ DataContext="{Binding TabControlDemo,Source={StaticResource Locator}}"
+ xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
+ xmlns:interactivity="clr-namespace:HandyControl.Interactivity;assembly=HandyControl">
+
+
+
+
+
+
+
+
-
+
diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TabControlDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TabControlDemoViewModel.cs
new file mode 100644
index 00000000..d82c4254
--- /dev/null
+++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TabControlDemoViewModel.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Windows;
+using GalaSoft.MvvmLight;
+using HandyControl.Controls;
+using HandyControl.Data;
+#if netle40
+using GalaSoft.MvvmLight.Command;
+#else
+using GalaSoft.MvvmLight.CommandWpf;
+#endif
+
+namespace HandyControlDemo.ViewModel
+{
+ public class TabControlDemoViewModel : ViewModelBase
+ {
+ public RelayCommand ClosingCmd => new Lazy>(() =>
+ new RelayCommand(Closing)).Value;
+
+ private void Closing(CancelRoutedEventArgs args)
+ {
+ Growl.Info($"{(args.OriginalSource as TabItem)?.Header} Closing");
+ }
+
+ public RelayCommand ClosedCmd => new Lazy>(() =>
+ new RelayCommand(Closed)).Value;
+
+ private void Closed(RoutedEventArgs args)
+ {
+ Growl.Info($"{(args.OriginalSource as TabItem)?.Header} Closed");
+ }
+ }
+}
\ 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 c3c84631..44d62f42 100644
--- a/src/Shared/HandyControlDemo_Shared/ViewModel/ViewModelLocator.cs
+++ b/src/Shared/HandyControlDemo_Shared/ViewModel/ViewModelLocator.cs
@@ -34,6 +34,7 @@ namespace HandyControlDemo.ViewModel
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
+ SimpleIoc.Default.Register();
}
public static ViewModelLocator Instance => new Lazy(() =>
@@ -75,6 +76,8 @@ namespace HandyControlDemo.ViewModel
public SideMenuDemoViewModel SideMenuDemo => ServiceLocator.Current.GetInstance();
+ public TabControlDemoViewModel TabControlDemo => ServiceLocator.Current.GetInstance();
+
#endregion
}
}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Controls/TabControl/TabControl.cs b/src/Shared/HandyControl_Shared/Controls/TabControl/TabControl.cs
index fa7f1751..df114ca5 100644
--- a/src/Shared/HandyControl_Shared/Controls/TabControl/TabControl.cs
+++ b/src/Shared/HandyControl_Shared/Controls/TabControl/TabControl.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
@@ -30,7 +31,7 @@ namespace HandyControl.Controls
private TabPanel _headerPanel;
- private ScrollViewer _scrollviewerOverflow;
+ private ScrollViewer _scrollViewerOverflow;
private Button _buttonScrollLeft;
@@ -146,6 +147,36 @@ namespace HandyControl.Controls
set => SetValue(IsScrollableProperty, value);
}
+ ///
+ /// 是否显示溢出按钮
+ ///
+ public static readonly DependencyProperty ShowOverflowButtonProperty = DependencyProperty.Register(
+ "ShowOverflowButton", typeof(bool), typeof(TabControl), new PropertyMetadata(ValueBoxes.TrueBox));
+
+ ///
+ /// 是否显示溢出按钮
+ ///
+ public bool ShowOverflowButton
+ {
+ get => (bool) GetValue(ShowOverflowButtonProperty);
+ set => SetValue(ShowOverflowButtonProperty, value);
+ }
+
+ ///
+ /// 是否显示滚动按钮
+ ///
+ public static readonly DependencyProperty ShowScrollButtonProperty = DependencyProperty.Register(
+ "ShowScrollButton", typeof(bool), typeof(TabControl), new PropertyMetadata(ValueBoxes.FalseBox));
+
+ ///
+ /// 是否显示滚动按钮
+ ///
+ public bool ShowScrollButton
+ {
+ get => (bool) GetValue(ShowScrollButtonProperty);
+ set => SetValue(ShowScrollButtonProperty, value);
+ }
+
///
/// 可见的标签数量
///
@@ -164,7 +195,7 @@ namespace HandyControl.Controls
if (!IsEnableTabFill)
{
_itemShowCount = (int)(ActualWidth / TabItemWidth);
- _buttonOverflow.Show(Items.Count > 0 && Items.Count >= _itemShowCount);
+ _buttonOverflow?.Show(ShowOverflowButton && Items.Count > 0 && Items.Count >= _itemShowCount);
}
if (IsInternalAction)
@@ -214,7 +245,7 @@ namespace HandyControl.Controls
if (IsEnableTabFill) return;
_buttonOverflow = GetTemplateChild(OverflowButtonKey) as ContextMenuToggleButton;
- _scrollviewerOverflow = GetTemplateChild(OverflowScrollviewer) as ScrollViewer;
+ _scrollViewerOverflow = GetTemplateChild(OverflowScrollviewer) as ScrollViewer;
_buttonScrollLeft = GetTemplateChild(ScrollButtonLeft) as Button;
_buttonScrollRight = GetTemplateChild(ScrollButtonRight) as Button;
@@ -224,7 +255,7 @@ namespace HandyControl.Controls
if (_buttonOverflow != null)
{
_itemShowCount = (int)(ActualWidth / TabItemWidth);
- _buttonOverflow.Show(Items.Count > 0 && Items.Count >= _itemShowCount);
+ _buttonOverflow.Show(ShowOverflowButton && Items.Count > 0 && Items.Count >= _itemShowCount);
var menu = new ContextMenu
{
@@ -240,12 +271,12 @@ namespace HandyControl.Controls
private void Menu_Closed(object sender, RoutedEventArgs e) => _buttonOverflow.IsChecked = false;
private void ButtonScrollRight_Click(object sender, RoutedEventArgs e) =>
- _scrollviewerOverflow.ScrollToHorizontalOffsetInternal(Math.Min(
- _scrollviewerOverflow.CurrentHorizontalOffset + TabItemWidth, _scrollviewerOverflow.ScrollableWidth));
+ _scrollViewerOverflow.ScrollToHorizontalOffsetInternal(Math.Min(
+ _scrollViewerOverflow.CurrentHorizontalOffset + TabItemWidth, _scrollViewerOverflow.ScrollableWidth));
private void ButtonScrollLeft_Click(object sender, RoutedEventArgs e) =>
- _scrollviewerOverflow.ScrollToHorizontalOffsetInternal(Math.Max(
- _scrollviewerOverflow.CurrentHorizontalOffset - TabItemWidth, 0));
+ _scrollViewerOverflow.ScrollToHorizontalOffsetInternal(Math.Max(
+ _scrollViewerOverflow.CurrentHorizontalOffset - TabItemWidth, 0));
private void ButtonOverflow_Click(object sender, RoutedEventArgs e)
{
@@ -288,11 +319,37 @@ namespace HandyControl.Controls
}
}
- internal double GetHorizontalOffset() => _scrollviewerOverflow?.CurrentHorizontalOffset ?? 0;
+ internal double GetHorizontalOffset() => _scrollViewerOverflow?.CurrentHorizontalOffset ?? 0;
- internal void UpdateScroll() => _scrollviewerOverflow?.RaiseEvent(new MouseWheelEventArgs(Mouse.PrimaryDevice, Environment.TickCount, 0)
+ internal void UpdateScroll() => _scrollViewerOverflow?.RaiseEvent(new MouseWheelEventArgs(Mouse.PrimaryDevice, Environment.TickCount, 0)
{
RoutedEvent = MouseWheelEvent
});
+
+ internal void CloseAllItems() => CloseOtherItems(null);
+
+ internal void CloseOtherItems(TabItem currentItem)
+ {
+ IsInternalAction = true;
+ var enumerator = ((IEnumerable)Items).GetEnumerator();
+ while (enumerator.MoveNext())
+ {
+ var item = enumerator.Current;
+ if (!Equals(item, currentItem) && item != null)
+ {
+ var argsClosing = new CancelRoutedEventArgs(TabItem.ClosingEvent, item);
+ var elment = item as UIElement;
+ if (elment != null)
+ {
+ elment.RaiseEvent(argsClosing);
+ if (argsClosing.Cancel) return;
+ }
+
+ elment?.RaiseEvent(new RoutedEventArgs(TabItem.ClosedEvent, item));
+ Items.Remove(item);
+ enumerator = ((IEnumerable)Items).GetEnumerator();
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs b/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs
index 02f22938..4749e62d 100644
--- a/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs
+++ b/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs
@@ -1,10 +1,10 @@
using System;
-using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
+using HandyControl.Data;
using HandyControl.Interactivity;
using HandyControl.Tools;
@@ -130,26 +130,11 @@ namespace HandyControl.Controls
public TabItem()
{
- CommandBindings.Add(new CommandBinding(ControlCommands.Close, Close));
- CommandBindings.Add(new CommandBinding(ControlCommands.CloseAll, (s, e) =>
- {
- TabControlParent.IsInternalAction = true;
- TabControlParent.Items.Clear();
- }));
- CommandBindings.Add(new CommandBinding(ControlCommands.CloseOther, (s, e) =>
- {
- TabControlParent.IsInternalAction = true;
- var enumerator = ((IEnumerable)TabControlParent.Items).GetEnumerator();
- while (enumerator.MoveNext())
- {
- var item = enumerator.Current;
- if (!Equals(item) && item != null)
- {
- TabControlParent.Items.Remove(item);
- enumerator = ((IEnumerable)TabControlParent.Items).GetEnumerator();
- }
- }
- }));
+ CommandBindings.Add(new CommandBinding(ControlCommands.Close, (s, e) => Close()));
+ CommandBindings.Add(new CommandBinding(ControlCommands.CloseAll,
+ (s, e) => { TabControlParent.CloseAllItems(); }));
+ CommandBindings.Add(new CommandBinding(ControlCommands.CloseOther,
+ (s, e) => { TabControlParent.CloseOtherItems(this); }));
}
private TabControl TabControlParent => new Lazy(() => ItemsControl.ItemsControlFromItemContainer(this) as TabControl).Value;
@@ -161,11 +146,12 @@ namespace HandyControl.Controls
Focus();
}
- ///
- /// 关闭
- ///
- private void Close(object sender, RoutedEventArgs e)
+ internal void Close()
{
+ var argsClosing = new CancelRoutedEventArgs(ClosingEvent, this);
+ RaiseEvent(argsClosing);
+ if (argsClosing.Cancel) return;
+
if (TabControlParent.IsEnableAnimation)
{
TabPanel.ClearValue(TabPanel.FluidMoveDurationProperty);
@@ -175,6 +161,7 @@ namespace HandyControl.Controls
TabPanel.FluidMoveDuration = new Duration(TimeSpan.FromSeconds(0));
}
TabControlParent.IsInternalAction = true;
+ RaiseEvent(new RoutedEventArgs(ClosedEvent, this));
TabControlParent.Items.Remove(this);
}
@@ -300,5 +287,21 @@ namespace HandyControl.Controls
return result > maxIndex ? maxIndex : result;
}
+
+ public static readonly RoutedEvent ClosingEvent = EventManager.RegisterRoutedEvent("Closing", RoutingStrategy.Bubble, typeof(EventHandler), typeof(TabItem));
+
+ public event EventHandler Closing
+ {
+ add => AddHandler(ClosingEvent, value);
+ remove => RemoveHandler(ClosingEvent, value);
+ }
+
+ public static readonly RoutedEvent ClosedEvent = EventManager.RegisterRoutedEvent("Closed", RoutingStrategy.Bubble, typeof(EventHandler), typeof(TabItem));
+
+ public event EventHandler Closed
+ {
+ add => AddHandler(ClosedEvent, value);
+ remove => RemoveHandler(ClosedEvent, value);
+ }
}
}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml
index 0b4617d2..cf30ac28 100644
--- a/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Styles/TabControl.xaml
@@ -115,7 +115,7 @@
-
+
@@ -134,12 +134,13 @@
-
+
-
+
+