RibbonTabHeader support for Collapsed

This commit is contained in:
NaBian committed 2022-06-13 23:06:48 +08:00
1 parent 03a4777d29
commit 740ac6d4a3
4 files changed
+53 -17

No files matched your search

@@ -2,7 +2,6 @@
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using HandyControl.Data;
using HandyControl.Tools;
namespace HandyControl.Controls
{
@@ -75,11 +74,16 @@ namespace HandyControl.Controls
Ribbon?.NotifyTabHeaderChanged();
}
protected override DependencyObject GetContainerForItemOverride() => new RibbonGroup();
protected override bool IsItemItsOwnContainerOverride(object item) => item is RibbonGroup;
private static void OnVisibilityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ribbonTab = (RibbonTab) d;
var ribbon = ribbonTab.Ribbon;
ribbonTab.RibbonTabHeader?.CoerceValue(VisibilityProperty);
var ribbon = ribbonTab.Ribbon;
if (ribbon == null ||
!ribbonTab.IsSelected ||
(Visibility) e.OldValue != Visibility.Visible ||
@@ -90,9 +94,5 @@ namespace HandyControl.Controls
ribbon.ResetSelection();
}
protected override DependencyObject GetContainerForItemOverride() => new RibbonGroup();
protected override bool IsItemItsOwnContainerOverride(object item) => item is RibbonGroup;
}
}
@@ -25,16 +25,15 @@ namespace HandyControl.Controls
}
}
static RibbonTabHeader()
{
VisibilityProperty.OverrideMetadata(typeof(RibbonTabHeader), new FrameworkPropertyMetadata(null, CoerceVisibility));
}
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
"IsSelected", typeof(bool), typeof(RibbonTabHeader),
new PropertyMetadata(ValueBoxes.FalseBox, OnIsSelectedChanged, CoerceIsSelected));
private static object CoerceIsSelected(DependencyObject d, object basevalue)
{
var ribbonTab = ((RibbonTabHeader) d).RibbonTab;
return ribbonTab != null ? ValueBoxes.BooleanBox(ribbonTab.IsSelected) : basevalue;
}
private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((RibbonTabHeader) d).OnIsSelectedChanged((bool) e.OldValue, (bool) e.NewValue);
@@ -49,6 +48,7 @@ namespace HandyControl.Controls
internal void PrepareRibbonTabHeader()
{
CoerceValue(IsSelectedProperty);
CoerceValue(VisibilityProperty);
}
protected virtual void OnIsSelectedChanged(bool oldIsSelected, bool newIsSelected)
@@ -80,5 +80,17 @@ namespace HandyControl.Controls
ribbonTab.IsSelected = true;
}
private static object CoerceIsSelected(DependencyObject d, object basevalue)
{
var ribbonTab = ((RibbonTabHeader) d).RibbonTab;
return ribbonTab != null ? ValueBoxes.BooleanBox(ribbonTab.IsSelected) : basevalue;
}
private static object CoerceVisibility(DependencyObject d, object basevalue)
{
var ribbonTab = ((RibbonTabHeader) d).RibbonTab;
return ribbonTab != null ? ValueBoxes.VisibilityBox(ribbonTab.Visibility) : basevalue;
}
}
}
@@ -1,4 +1,6 @@
using System.Windows.Controls;
using System;
using System.Windows;
using System.Windows.Controls;
namespace HandyControl.Data;
@@ -15,10 +17,18 @@ internal static class ValueBoxes
internal static object HorizontalBox = Orientation.Horizontal;
internal static object VisibleBox = Visibility.Visible;
internal static object CollapsedBox = Visibility.Collapsed;
internal static object HiddenBox = Visibility.Hidden;
internal static object Double0Box = .0;
internal static object Double01Box = .1;
internal static object Double0Box = .0;
internal static object Double1Box = 1.0;
internal static object Double10Box = 10.0;
@@ -47,4 +57,15 @@ internal static class ValueBoxes
internal static object OrientationBox(Orientation value) =>
value == Orientation.Horizontal ? HorizontalBox : VerticalBox;
internal static object VisibilityBox(Visibility value)
{
return value switch
{
Visibility.Visible => VisibleBox,
Visibility.Hidden => HiddenBox,
Visibility.Collapsed => CollapsedBox,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, null)
};
}
}
@@ -51,6 +51,7 @@
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Foreground" Value="{DynamicResource SecondaryTextBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource TitleBrush}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="{StaticResource DefaultControlPadding}"/>
<Setter Property="MinHeight" Value="{StaticResource DefaultControlHeight}"/>
@@ -59,10 +60,12 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:RibbonTabHeader">
<hc:SimplePanel x:Name="templateRoot" SnapsToDevicePixels="true">
<Border x:Name="BorderBottom" Visibility="{Binding IsSelected,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0,0,2" Background="{TemplateBinding Background}" Margin="12,0,12,2"/>
<ContentPresenter x:Name="ContentPresenter" Focusable="False" HorizontalAlignment="Center" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
</hc:SimplePanel>
<Border Background="{TemplateBinding Background}">
<hc:SimplePanel x:Name="templateRoot" SnapsToDevicePixels="true">
<Border x:Name="BorderBottom" Visibility="{Binding IsSelected,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0,0,2" Margin="12,0,12,2"/>
<ContentPresenter x:Name="ContentPresenter" Focusable="False" HorizontalAlignment="Center" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
</hc:SimplePanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>