SPARK-2293 / SPARK-2323 change right panel toolbar button click mode to 'Pressed' (i.e., select on mouse down)

This commit is contained in:
John Colvin committed 2019-04-26 11:25:24 -05:00
1 parent b81459cdf7
commit cee4d65d38
2 files changed
+73 -22

No files matched your search

@@ -231,10 +231,6 @@
</Style>
<!--MenuItem Storyboards-->
<Storyboard x:Key="StackPressed">
<DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Control.BorderBrush).(SolidColorBrush.Opacity)" BeginTime="0" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Control.Background).(LinearGradientBrush.Opacity)" BeginTime="0" Duration="0" To="1"/>
</Storyboard>
<Storyboard x:Key="TabCheckedStoryboard">
<!--CheckMark Opacity-->
<DoubleAnimation Storyboard.TargetName="CheckMark" Storyboard.TargetProperty="(UIElement.Opacity)" BeginTime="0" Duration="0" To="1"/>
@@ -261,6 +257,7 @@
</Storyboard>
<Style x:Key="RightPanel.MenuItem" TargetType="MenuItem">
<Setter Property="c:MenuItemEx.ClickMode" Value="Press"/>
<Setter Property="BorderThickness" Value="1,0"/>
<Setter Property="IsCheckable" Value="True"/>
<Setter Property="Focusable" Value="False"/>
@@ -315,8 +312,13 @@
<DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Control.Background).(LinearGradientBrush.Opacity)" BeginTime="0" Duration="0" To="0.5"/>
</Storyboard>
</VisualState>
<VisualState Name="StackUncheckedPressed" Storyboard="{StaticResource StackPressed}"/>
<VisualState Name="StackCheckedNormal">
<VisualState Name="StackUncheckedPressed">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Control.BorderBrush).(SolidColorBrush.Opacity)" BeginTime="0" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Control.Background).(LinearGradientBrush.Opacity)" BeginTime="0" Duration="0" To="1"/>
</Storyboard>
</VisualState>
<VisualState Name="StackCheckedNormal">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="CheckMark" Storyboard.TargetProperty="(UIElement.Opacity)" BeginTime="0" Duration="0" To="1"/>
<ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Control.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" BeginTime="0" Duration="0" To="#800080FF"/>
@@ -333,7 +335,13 @@
<DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Control.Background).(LinearGradientBrush.Opacity)" BeginTime="0" Duration="0" To="0.5"/>
</Storyboard>
</VisualState>
<VisualState Name="StackCheckedPressed" Storyboard="{StaticResource StackPressed}"/>
<VisualState Name="StackCheckedPressed">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="CheckMark" Storyboard.TargetProperty="(UIElement.Opacity)" BeginTime="0" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Control.BorderBrush).(SolidColorBrush.Opacity)" BeginTime="0" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Control.Background).(LinearGradientBrush.Opacity)" BeginTime="0" Duration="0" To="1"/>
</Storyboard>
</VisualState>
<!--Tab-->
<VisualState Name="TabUncheckedNormal">
<Storyboard>
@@ -1,22 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace mbts.ui.controls
{
public static class MenuItemEx
{
namespace mbts.ui.controls {
static class MenuItemEx {
#region IsThreeState Property
public static readonly DependencyProperty IsThreeStateProperty = DependencyProperty.RegisterAttached("IsThreeState", typeof(bool), typeof(MenuItemEx), new PropertyMetadata(false, OnIsThreeStateChanged));
@@ -45,5 +34,59 @@ namespace mbts.ui.controls
public static void SetIsChecked(MenuItem target, bool? value) { target.SetValue(IsCheckedProperty, value.HasValue ? (object)value.Value : null); }
#endregion
#region ClickMode
public static readonly DependencyProperty ClickModeProperty =
DependencyProperty.RegisterAttached("ClickMode", typeof(ClickMode), typeof(MenuItemEx),
new PropertyMetadata(ClickMode.Release,
(d, e) => {
if (!(d is MenuItem m))
return;
switch ((ClickMode)e.OldValue) {
case ClickMode.Press:
m.PreviewMouseLeftButtonDown -= _ClickMode.ToggleIsChecked;
m.PreviewMouseLeftButtonUp -= _ClickMode.Cancel;
break;
case ClickMode.Hover:
// TODO
break;
case ClickMode.Release:
// default behavior (no action needed)
break;
}
switch ((ClickMode)e.NewValue) {
case ClickMode.Press:
m.PreviewMouseLeftButtonDown += _ClickMode.ToggleIsChecked;
m.PreviewMouseLeftButtonUp += _ClickMode.Cancel;
break;
case ClickMode.Hover:
// TODO
break;
case ClickMode.Release:
// default behavior (no action needed)
break;
}
}));
public static ClickMode GetClickMode(DependencyObject d) => (ClickMode)d.GetValue(ClickModeProperty);
public static void SetClickMode(DependencyObject d, ClickMode value) => d.SetValue(ClickModeProperty, value);
#endregion
static class _ClickMode {
public static void ToggleIsChecked(object sender, MouseButtonEventArgs e) {
if (sender is MenuItem m) {
e.Handled = true;
if (m.IsCheckable) {
m.SetCurrentValue(MenuItem.IsCheckedProperty, !m.IsChecked);
}
// https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/MenuItem.cs,bcd8e018ced72cc5
// 'MenuItem.HandleMouseUp' begins a call tree that eventually enqueues a DispatcherOperationCallback (with 'Render' priority), to execute the MenuItem's Command.
m.Dispatcher.InvokeAsync(() => m.Command.TryExecuteIfCan(m.CommandParameter), DispatcherPriority.Render);
}
}
public static void Cancel(object sender, MouseButtonEventArgs e) =>
e.Handled = true;
}
}
}
}