From 05f9e22ccb504f4abdd5bad2d18181e9003236b0 Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Tue, 21 Mar 2017 16:28:07 +0100 Subject: [PATCH 01/12] Add new Underlined attached property New property to control the type of the underline which can be TabItem or TabPanel (with TabItem) Add Obsolete tag to IsUnderlined property. --- .../Controls/Helper/TabControlHelper.cs | 59 +++++++++++++++++-- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/src/MahApps.Metro/MahApps.Metro.Shared/Controls/Helper/TabControlHelper.cs b/src/MahApps.Metro/MahApps.Metro.Shared/Controls/Helper/TabControlHelper.cs index e99ac86aae..6bdbb74c82 100644 --- a/src/MahApps.Metro/MahApps.Metro.Shared/Controls/Helper/TabControlHelper.cs +++ b/src/MahApps.Metro/MahApps.Metro.Shared/Controls/Helper/TabControlHelper.cs @@ -1,36 +1,83 @@ -using System.Windows; +using System; +using System.ComponentModel; +using System.Windows; using System.Windows.Controls; +using System.Windows.Controls.Primitives; namespace MahApps.Metro.Controls { - using System.ComponentModel; + /// + /// Specifies the underline position of a TabControl. + /// + public enum UnderlinedType + { + None, + TabItem, + TabPanel + } public static class TabControlHelper { /// - /// Defines whether the underline below the is shown or not. + /// Defines whether the underline below the is shown or not. /// + [Obsolete(@"This property will be deleted in the next release. You should now use the Underlined attached property.")] public static readonly DependencyProperty IsUnderlinedProperty = - DependencyProperty.RegisterAttached("IsUnderlined", typeof(bool), typeof(TabControlHelper), new PropertyMetadata(false)); + DependencyProperty.RegisterAttached("IsUnderlined", + typeof(bool), + typeof(TabControlHelper), + new PropertyMetadata(false, + (o, e) => + { + var element = o as UIElement; + if (element != null && e.OldValue != e.NewValue && e.NewValue is bool) + { + TabControlHelper.SetUnderlined(element, (bool)e.NewValue ? UnderlinedType.TabItem : UnderlinedType.None); + } + })); [Category(AppName.MahApps)] [AttachedPropertyBrowsableForType(typeof(TabControl))] - [AttachedPropertyBrowsableForType(typeof(TabItem))] + [Obsolete(@"This property will be deleted in the next release. You should now use the Underlined attached property.")] public static bool GetIsUnderlined(UIElement element) { return (bool)element.GetValue(IsUnderlinedProperty); } + [Obsolete(@"This property will be deleted in the next release. You should now use the Underlined attached property.")] public static void SetIsUnderlined(UIElement element, bool value) { element.SetValue(IsUnderlinedProperty, value); } + /// + /// Defines whether the underline below the or is shown or not. + /// + public static readonly DependencyProperty UnderlinedProperty = + DependencyProperty.RegisterAttached("Underlined", + typeof(UnderlinedType), + typeof(TabControlHelper), + new PropertyMetadata(UnderlinedType.None)); + + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(TabControl))] + public static UnderlinedType GetUnderlined(UIElement element) + { + return (UnderlinedType)element.GetValue(UnderlinedProperty); + } + + public static void SetUnderlined(UIElement element, UnderlinedType value) + { + element.SetValue(UnderlinedProperty, value); + } + /// /// This property can be used to set the Transition for animated TabControls /// public static readonly DependencyProperty TransitionProperty = - DependencyProperty.RegisterAttached("Transition", typeof(TransitionType), typeof(TabControlHelper), + DependencyProperty.RegisterAttached("Transition", + typeof(TransitionType), + typeof(TabControlHelper), new FrameworkPropertyMetadata(TransitionType.Default, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.Inherits)); [Category(AppName.MahApps)] From 9a63465bbd742b5b7a80084d33651dfd745698a8 Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Tue, 21 Mar 2017 16:29:33 +0100 Subject: [PATCH 02/12] New Underline content control This control can be used for underline scenarios. --- .../Controls/Underline.cs | 78 +++++++++++++++++++ .../MahApps.Metro.Shared.projitems | 1 + .../MahApps.Metro/MahApps.Metro.NET40.csproj | 4 + .../MahApps.Metro/MahApps.Metro.NET45.csproj | 4 + .../MahApps.Metro/Themes/Generic.xaml | 1 + .../MahApps.Metro/Themes/Underline.xaml | 34 ++++++++ 6 files changed, 122 insertions(+) create mode 100644 src/MahApps.Metro/MahApps.Metro.Shared/Controls/Underline.cs create mode 100644 src/MahApps.Metro/MahApps.Metro/Themes/Underline.xaml diff --git a/src/MahApps.Metro/MahApps.Metro.Shared/Controls/Underline.cs b/src/MahApps.Metro/MahApps.Metro.Shared/Controls/Underline.cs new file mode 100644 index 0000000000..539fbe482c --- /dev/null +++ b/src/MahApps.Metro/MahApps.Metro.Shared/Controls/Underline.cs @@ -0,0 +1,78 @@ +using System; +using System.Windows; +using System.Windows.Controls; + +namespace MahApps.Metro.Controls +{ + [TemplatePart(Name = UnderlineBorderPartName, Type = typeof(Border))] + public class Underline : ContentControl + { + public const string UnderlineBorderPartName = "PART_UnderlineBorder"; + private Border _underlineBorder; + + public static readonly DependencyProperty PlacementProperty = + DependencyProperty.Register(nameof(Placement), + typeof(Dock), + typeof(Underline), + new PropertyMetadata(default(Dock), (o, e) => { (o as Underline)?.ApplyBorderProperties(); })); + + public Dock Placement + { + get { return (Dock)this.GetValue(PlacementProperty); } + set { this.SetValue(PlacementProperty, value); } + } + + public static readonly DependencyProperty LineThicknessProperty = + DependencyProperty.Register(nameof(LineThickness), + typeof(double), + typeof(Underline), + new PropertyMetadata(1d, (o, e) => { (o as Underline)?.ApplyBorderProperties(); })); + + public double LineThickness + { + get { return (double)this.GetValue(LineThicknessProperty); } + set { this.SetValue(LineThicknessProperty, value); } + } + + static Underline() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(Underline), new FrameworkPropertyMetadata(typeof(Underline))); + } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + this._underlineBorder = this.GetTemplateChild(UnderlineBorderPartName) as Border; + this.ApplyBorderProperties(); + } + + private void ApplyBorderProperties() + { + if (this._underlineBorder == null) + { + return; + } + + this._underlineBorder.BorderThickness = new Thickness(); + switch (this.Placement) + { + case Dock.Left: + this._underlineBorder.BorderThickness = new Thickness(this.LineThickness, 0d, 0d, 0d); + break; + case Dock.Top: + this._underlineBorder.BorderThickness = new Thickness(0d, this.LineThickness, 0d, 0d); + break; + case Dock.Right: + this._underlineBorder.BorderThickness = new Thickness(0d, 0d, this.LineThickness, 0d); + break; + case Dock.Bottom: + this._underlineBorder.BorderThickness = new Thickness(0d, 0d, 0d, this.LineThickness); + break; + default: + throw new ArgumentOutOfRangeException(); + } + this._underlineBorder.InvalidateVisual(); + } + } +} \ No newline at end of file diff --git a/src/MahApps.Metro/MahApps.Metro.Shared/MahApps.Metro.Shared.projitems b/src/MahApps.Metro/MahApps.Metro.Shared/MahApps.Metro.Shared.projitems index 74abb43b7a..3347a1cc4e 100644 --- a/src/MahApps.Metro/MahApps.Metro.Shared/MahApps.Metro.Shared.projitems +++ b/src/MahApps.Metro/MahApps.Metro.Shared/MahApps.Metro.Shared.projitems @@ -131,6 +131,7 @@ + diff --git a/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET40.csproj b/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET40.csproj index 7143eeabcf..932b9090a6 100644 --- a/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET40.csproj +++ b/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET40.csproj @@ -536,6 +536,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET45.csproj b/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET45.csproj index eaa1bb456f..3898758e78 100644 --- a/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET45.csproj +++ b/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET45.csproj @@ -536,6 +536,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + MSBuild:Compile Designer diff --git a/src/MahApps.Metro/MahApps.Metro/Themes/Generic.xaml b/src/MahApps.Metro/MahApps.Metro/Themes/Generic.xaml index f0a5c4a3d9..5a718a8fbb 100644 --- a/src/MahApps.Metro/MahApps.Metro/Themes/Generic.xaml +++ b/src/MahApps.Metro/MahApps.Metro/Themes/Generic.xaml @@ -6,6 +6,7 @@ + diff --git a/src/MahApps.Metro/MahApps.Metro/Themes/Underline.xaml b/src/MahApps.Metro/MahApps.Metro/Themes/Underline.xaml new file mode 100644 index 0000000000..96780e231e --- /dev/null +++ b/src/MahApps.Metro/MahApps.Metro/Themes/Underline.xaml @@ -0,0 +1,34 @@ + + + + + \ No newline at end of file From a7cb005412c2d84753f72ff581a1344f6d7bdc09 Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Tue, 21 Mar 2017 16:31:11 +0100 Subject: [PATCH 03/12] Use new Underline control and Underlined property Use the new stuff at TabControl (TabControl) and MetroTabControl (MetroTabItem) --- .../Styles/Controls.TabControl.xaml | 198 +++++++++--------- .../MahApps.Metro/Themes/MetroTabControl.xaml | 46 ++-- .../MahApps.Metro/Themes/MetroTabItem.xaml | 130 +++++------- 3 files changed, 181 insertions(+), 193 deletions(-) diff --git a/src/MahApps.Metro/MahApps.Metro/Styles/Controls.TabControl.xaml b/src/MahApps.Metro/MahApps.Metro/Styles/Controls.TabControl.xaml index c7712af857..4eb5606a20 100644 --- a/src/MahApps.Metro/MahApps.Metro/Styles/Controls.TabControl.xaml +++ b/src/MahApps.Metro/MahApps.Metro/Styles/Controls.TabControl.xaml @@ -5,7 +5,7 @@