RibbonGroup support for LauncherButton
This commit is contained in:
1 parent
1e07220d47
commit
82f6926416
7 files changed
+146
-10
No files matched your search
@@ -4,8 +4,11 @@ using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Data.Enum;
|
||||
using HandyControl.Expression.Drawing;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControl.Controls;
|
||||
|
||||
@@ -13,6 +16,8 @@ public class Poptip : AdornerElement
|
||||
{
|
||||
private readonly Popup _popup;
|
||||
|
||||
private DispatcherTimer _openTimer;
|
||||
|
||||
public Poptip()
|
||||
{
|
||||
_popup = new Popup
|
||||
@@ -172,6 +177,15 @@ public class Poptip : AdornerElement
|
||||
set => SetValue(IsOpenProperty, ValueBoxes.BooleanBox(value));
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty DelayProperty = DependencyProperty.Register(
|
||||
"Delay", typeof(double), typeof(Poptip), new PropertyMetadata(1000.0), ValidateHelper.IsInRangeOfPosDoubleIncludeZero);
|
||||
|
||||
public double Delay
|
||||
{
|
||||
get => (double) GetValue(DelayProperty);
|
||||
set => SetValue(DelayProperty, value);
|
||||
}
|
||||
|
||||
public static Poptip Default => new();
|
||||
|
||||
protected sealed override void OnTargetChanged(FrameworkElement element, bool isNew)
|
||||
@@ -290,8 +304,43 @@ public class Poptip : AdornerElement
|
||||
_popup.PlacementTarget = Target;
|
||||
UpdateLocation();
|
||||
}
|
||||
_popup.IsOpen = isShow;
|
||||
Target.SetCurrentValue(IsOpenProperty, isShow);
|
||||
|
||||
ResetTimer();
|
||||
|
||||
var delay = Delay;
|
||||
if (!isShow || HitMode != HitMode.Hover || MathHelper.IsVerySmall(delay))
|
||||
{
|
||||
|
||||
_popup.IsOpen = isShow;
|
||||
Target.SetCurrentValue(IsOpenProperty, isShow);
|
||||
}
|
||||
else
|
||||
{
|
||||
_openTimer = new DispatcherTimer
|
||||
{
|
||||
Interval = TimeSpan.FromMilliseconds(delay)
|
||||
};
|
||||
|
||||
_openTimer.Tick += OpenTimer_Tick;
|
||||
_openTimer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetTimer()
|
||||
{
|
||||
if (_openTimer != null)
|
||||
{
|
||||
_openTimer.Stop();
|
||||
_openTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
_popup.IsOpen = true;
|
||||
Target.SetCurrentValue(IsOpenProperty, true);
|
||||
|
||||
ResetTimer();
|
||||
}
|
||||
|
||||
private void Element_MouseEnter(object sender, MouseEventArgs e)
|
||||
|
||||
@@ -73,6 +73,11 @@ namespace HandyControl.Controls
|
||||
}
|
||||
|
||||
var animation = isDropDownOpen ? CreateAnimation(0, ContentHeight) : CreateAnimation(ContentHeight, 0);
|
||||
animation.Completed += (s, e) =>
|
||||
{
|
||||
SwitchCurrentTabContentVisibility(isDropDownOpen);
|
||||
};
|
||||
|
||||
_contentPanel.BeginAnimation(HeightProperty, animation);
|
||||
}
|
||||
|
||||
@@ -100,6 +105,7 @@ namespace HandyControl.Controls
|
||||
var animation = isMinimized
|
||||
? CreateAnimation(_originHeight, _tabHeaderItemsControl.ActualHeight)
|
||||
: CreateAnimation(_tabHeaderItemsControl.ActualHeight, _originHeight);
|
||||
|
||||
_rootPanel.BeginAnimation(HeightProperty, animation);
|
||||
}
|
||||
|
||||
@@ -331,6 +337,29 @@ namespace HandyControl.Controls
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void SwitchCurrentTabContentVisibility(bool isVisible)
|
||||
{
|
||||
var tab = GetCurrentTab();
|
||||
tab?.SwitchContentVisibility(isVisible);
|
||||
}
|
||||
|
||||
private RibbonTab GetCurrentTab()
|
||||
{
|
||||
var index = SelectedIndex;
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ItemContainerGenerator.ContainerFromIndex(index) is RibbonTab ribbonTab)
|
||||
{
|
||||
return ribbonTab;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void InitializeSelection()
|
||||
{
|
||||
if (!IsDropDownOpen)
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Interactivity;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class RibbonGroup : HeaderedItemsControl
|
||||
{
|
||||
public RibbonGroup()
|
||||
{
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.More, LauncherButton_OnClick));
|
||||
}
|
||||
|
||||
private void LauncherButton_OnClick(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
OnLauncherClick(new RoutedEventArgs(LauncherClickEvent, this));
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ShowLauncherButtonProperty = DependencyProperty.Register(
|
||||
"ShowLauncherButton", typeof(bool), typeof(RibbonGroup), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
@@ -23,5 +35,26 @@ namespace HandyControl.Controls
|
||||
get => (bool) GetValue(ShowSplitterProperty);
|
||||
set => SetValue(ShowSplitterProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty LauncherPoptipProperty = DependencyProperty.Register(
|
||||
"LauncherPoptip", typeof(Poptip), typeof(RibbonGroup), new PropertyMetadata(default(Poptip)));
|
||||
|
||||
public Poptip LauncherPoptip
|
||||
{
|
||||
get => (Poptip) GetValue(LauncherPoptipProperty);
|
||||
set => SetValue(LauncherPoptipProperty, value);
|
||||
}
|
||||
|
||||
public static readonly RoutedEvent LauncherClickEvent =
|
||||
EventManager.RegisterRoutedEvent("LauncherClick", RoutingStrategy.Bubble,
|
||||
typeof(RoutedEventHandler), typeof(RibbonGroup));
|
||||
|
||||
public event RoutedEventHandler LauncherClick
|
||||
{
|
||||
add => AddHandler(LauncherClickEvent, value);
|
||||
remove => RemoveHandler(LauncherClickEvent, value);
|
||||
}
|
||||
|
||||
protected virtual void OnLauncherClick(RoutedEventArgs e) => RaiseEvent(e);
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,17 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
[TemplatePart(Name = RootContainer, Type = typeof(UIElement))]
|
||||
public class RibbonTab : HeaderedItemsControl
|
||||
{
|
||||
private const string RootContainer = "PART_RootContainer";
|
||||
|
||||
private UIElement _rootContainer;
|
||||
|
||||
public Ribbon Ribbon => Ribbon.GetRibbon(this);
|
||||
|
||||
internal RibbonTabHeader RibbonTabHeader
|
||||
@@ -48,10 +54,16 @@ namespace HandyControl.Controls
|
||||
var ribbonTab = (RibbonTab) d;
|
||||
if (ribbonTab.IsSelected)
|
||||
{
|
||||
if (ribbonTab.Ribbon.IsDropDownOpen)
|
||||
{
|
||||
ribbonTab.SwitchContentVisibility(true);
|
||||
}
|
||||
|
||||
ribbonTab.OnSelected(new RoutedEventArgs(Selector.SelectedEvent, ribbonTab));
|
||||
}
|
||||
else
|
||||
{
|
||||
ribbonTab.SwitchContentVisibility(false);
|
||||
ribbonTab.OnUnselected(new RoutedEventArgs(Selector.UnselectedEvent, ribbonTab));
|
||||
}
|
||||
|
||||
@@ -64,6 +76,16 @@ namespace HandyControl.Controls
|
||||
set => SetValue(IsSelectedProperty, value);
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
_rootContainer = GetTemplateChild(RootContainer) as UIElement;
|
||||
|
||||
SwitchContentVisibility(IsSelected);
|
||||
}
|
||||
|
||||
internal void SwitchContentVisibility(bool isVisible) => _rootContainer?.Show(isVisible);
|
||||
|
||||
protected virtual void OnSelected(RoutedEventArgs e) => RaiseEvent(e);
|
||||
|
||||
protected virtual void OnUnselected(RoutedEventArgs e) => RaiseEvent(e);
|
||||
|
||||
Reference in new issue
Block a user