From 92260230d888242e5f10f3e906a7d6237d8afc0c Mon Sep 17 00:00:00 2001 From: "lukas.f" Date: Tue, 2 May 2017 21:27:45 +0200 Subject: [PATCH 1/3] Remove GridSplitterGripper to allow control of tab behavior and simplify visual tree. --- .../GridSplitter/GridSplitter.Events.cs | 47 +++++----- .../GridSplitter/GridSplitter.Options.cs | 5 +- .../GridSplitter/GridSplitter.cs | 3 + .../GridSplitter/GridSplitter.xaml | 6 +- .../GridSplitter/GridSplitterGripper.cs | 85 ------------------- .../Microsoft.Toolkit.Uwp.UI.Controls.csproj | 1 - 6 files changed, 35 insertions(+), 112 deletions(-) delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitterGripper.cs diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Events.cs index 0f936ea30ff..5a7d7ca77cf 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Events.cs @@ -13,7 +13,9 @@ using Windows.System; using Windows.UI.Core; using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; namespace Microsoft.Toolkit.Uwp.UI.Controls { @@ -22,30 +24,22 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls /// public partial class GridSplitter { + // Symbols for GripperBar in Segoe MDL2 Assets + private const string GripperBarVertical = "\xE784"; + private const string GripperBarHorizontal = "\xE76F"; + private const string GripperDisplayFont = "Segoe MDL2 Assets"; + private void GridSplitter_Loaded(object sender, RoutedEventArgs e) { _resizeDirection = GetResizeDirection(); _resizeBehavior = GetResizeBehavior(); - GridSplitterGripper gripper; - // Adding Grip to Grid Splitter if (Element == default(UIElement)) { - gripper = new GridSplitterGripper( - _resizeDirection, - GripperForeground); + CreateGripperDisplay(); + Element = _gripperDisplay; } - else - { - var content = Element; - Element = null; - gripper = new GridSplitterGripper(content, _resizeDirection); - } - - Element = gripper; - - gripper.KeyDown += Gripper_KeyDown; var hoverWrapper = new GripperHoverWrapper( CursorBehavior == SplitterCursorBehavior.ChangeOnSplitterHover @@ -60,15 +54,24 @@ private void GridSplitter_Loaded(object sender, RoutedEventArgs e) _hoverWrapper = hoverWrapper; } - private void Gripper_KeyDown(object sender, KeyRoutedEventArgs e) + private void CreateGripperDisplay() { - var gripper = sender as GridSplitterGripper; - - if (gripper == null) + if (_gripperDisplay == null) { - return; + var gripperText = _resizeDirection == GridResizeDirection.Columns ? GripperBarVertical : GripperBarHorizontal; + _gripperDisplay = new TextBlock + { + FontFamily = new FontFamily(GripperDisplayFont), + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + Foreground = GripperForeground, + Text = gripperText + }; } + } + private void GridSplitter_KeyDown(object sender, KeyRoutedEventArgs e) + { var step = 1; var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control); if (ctrl.HasFlag(CoreVirtualKeyStates.Down)) @@ -76,7 +79,7 @@ private void Gripper_KeyDown(object sender, KeyRoutedEventArgs e) step = 5; } - if (gripper.ResizeDirection == GridResizeDirection.Columns) + if (_resizeDirection == GridResizeDirection.Columns) { if (e.Key == VirtualKey.Left) { @@ -95,7 +98,7 @@ private void Gripper_KeyDown(object sender, KeyRoutedEventArgs e) return; } - if (gripper.ResizeDirection == GridResizeDirection.Rows) + if (_resizeDirection == GridResizeDirection.Rows) { if (e.Key == VirtualKey.Up) { diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Options.cs b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Options.cs index de2ccffcfa7..6b2d687b0f0 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Options.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Options.cs @@ -12,6 +12,7 @@ using Windows.UI.Core; using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; namespace Microsoft.Toolkit.Uwp.UI.Controls @@ -180,10 +181,10 @@ public SplitterCursorBehavior CursorBehavior private static void OnGripperForegroundPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var gridSplitter = (GridSplitter)d; - var grip = gridSplitter.Element as GridSplitterGripper; + var grip = gridSplitter._gripperDisplay; if (grip != null) { - grip.GripperForeground = gridSplitter.GripperForeground; + grip.Foreground = gridSplitter.GripperForeground; } } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.cs b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.cs index 93c8553ab6a..434c44d693d 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.cs @@ -31,6 +31,7 @@ public partial class GridSplitter : Control private GridResizeDirection _resizeDirection; private GridResizeBehavior _resizeBehavior; private GripperHoverWrapper _hoverWrapper; + private TextBlock _gripperDisplay; /// /// Gets the target parent grid from level @@ -174,9 +175,11 @@ protected override void OnApplyTemplate() // Unhook registered events Loaded -= GridSplitter_Loaded; + KeyDown -= GridSplitter_KeyDown; // Register Events Loaded += GridSplitter_Loaded; + KeyDown += GridSplitter_KeyDown; _hoverWrapper?.UnhookEvents(); diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.xaml b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.xaml index 83941258f32..009a8cbb193 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.xaml @@ -3,12 +3,14 @@ xmlns:local="using:Microsoft.Toolkit.Uwp.UI.Controls">