feat: add avalonia HyperlinkButton style.

This commit is contained in:
NaBian committed 2025-09-29 21:43:47 +08:00
1 parent 0c10c8234b
commit 78e729fdc5
24 files changed
+337 -50

No files matched your search

@@ -15,6 +15,16 @@ public class BackgroundSwitchElement
public static IBrush GetMouseHoverBackground(AvaloniaObject element) =>
element.GetValue(MouseHoverBackgroundProperty);
public static readonly AttachedProperty<IBrush> MouseHoverForegroundProperty =
AvaloniaProperty.RegisterAttached<BackgroundSwitchElement, AvaloniaObject, IBrush>("MouseHoverForeground",
defaultValue: Brushes.Transparent, inherits: true);
public static void SetMouseHoverForeground(AvaloniaObject element, IBrush value) =>
element.SetValue(MouseHoverForegroundProperty, value);
public static IBrush GetMouseHoverForeground(AvaloniaObject element) =>
element.GetValue(MouseHoverForegroundProperty);
public static readonly AttachedProperty<IBrush> MouseDownBackgroundProperty =
AvaloniaProperty.RegisterAttached<BackgroundSwitchElement, AvaloniaObject, IBrush>("MouseDownBackground",
defaultValue: Brushes.Transparent, inherits: true);
@@ -0,0 +1,73 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:ClassModifier="internal"
xmlns:hc="clr-namespace:HandyControl.Controls">
<ControlTheme x:Key="HyperlinkButtonBaseStyle"
TargetType="HyperlinkButton">
<Setter Property="Cursor"
Value="Hand" />
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" />
<Setter Property="BorderBrush"
Value="Transparent" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="Height"
Value="{StaticResource DefaultControlHeight}" />
<Setter Property="Padding"
Value="{StaticResource DefaultControlPadding}" />
<Setter Property="HorizontalAlignment"
Value="Center" />
<Setter Property="VerticalAlignment"
Value="Center" />
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="TextBlock.TextDecorations"
Value="Underline" />
<Setter Property="hc:BorderElement.CornerRadius"
Value="{StaticResource DefaultCornerRadius}" />
<Setter Property="CornerRadius"
Value="{Binding $self.(hc:BorderElement.CornerRadius)}" />
<Setter Property="Template">
<ControlTemplate>
<ContentPresenter x:Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
BackgroundSizing="{TemplateBinding BackgroundSizing}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Padding="{TemplateBinding Padding}"
RecognizesAccessKey="True"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover">
<Setter Property="Opacity"
Value="0.9" />
</Style>
<Style Selector="^:pressed">
<Setter Property="Opacity"
Value="0.6" />
</Style>
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
</ControlTheme>
<ControlTheme x:Key="{x:Type HyperlinkButton}"
BasedOn="{StaticResource HyperlinkButtonBaseStyle}"
TargetType="HyperlinkButton" />
</ResourceDictionary>
@@ -0,0 +1,62 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:ClassModifier="internal"
xmlns:hc="clr-namespace:HandyControl.Controls">
<Style Selector="HyperlinkButton.ghost">
<Setter Property="hc:BackgroundSwitchElement.MouseHoverBackground"
Value="{DynamicResource SecondaryRegionBrush}" />
<Setter Property="hc:BackgroundSwitchElement.MouseHoverForeground"
Value="{DynamicResource PrimaryTextBrush}" />
<Style Selector="^:pointerover">
<Setter Property="Background"
Value="{Binding $self.(hc:BackgroundSwitchElement.MouseHoverBackground)}" />
<Setter Property="Foreground"
Value="{Binding $self.(hc:BackgroundSwitchElement.MouseHoverForeground)}" />
</Style>
</Style>
<Style Selector="HyperlinkButton.primary">
<Setter Property="hc:BackgroundSwitchElement.MouseHoverBackground"
Value="{DynamicResource PrimaryBrush}" />
<Setter Property="hc:BackgroundSwitchElement.MouseHoverForeground"
Value="{DynamicResource TextIconBrush}" />
</Style>
<Style Selector="HyperlinkButton.success">
<Setter Property="hc:BackgroundSwitchElement.MouseHoverBackground"
Value="{DynamicResource SuccessBrush}" />
<Setter Property="hc:BackgroundSwitchElement.MouseHoverForeground"
Value="{DynamicResource TextIconBrush}" />
</Style>
<Style Selector="HyperlinkButton.info">
<Setter Property="hc:BackgroundSwitchElement.MouseHoverBackground"
Value="{DynamicResource InfoBrush}" />
<Setter Property="hc:BackgroundSwitchElement.MouseHoverForeground"
Value="{DynamicResource TextIconBrush}" />
</Style>
<Style Selector="HyperlinkButton.warning">
<Setter Property="hc:BackgroundSwitchElement.MouseHoverBackground"
Value="{DynamicResource WarningBrush}" />
<Setter Property="hc:BackgroundSwitchElement.MouseHoverForeground"
Value="{DynamicResource TextIconBrush}" />
</Style>
<Style Selector="HyperlinkButton.danger">
<Setter Property="hc:BackgroundSwitchElement.MouseHoverBackground"
Value="{DynamicResource DangerBrush}" />
<Setter Property="hc:BackgroundSwitchElement.MouseHoverForeground"
Value="{DynamicResource TextIconBrush}" />
</Style>
<Style Selector="HyperlinkButton.small">
<Setter Property="Height"
Value="20" />
<Setter Property="Padding"
Value="6,1" />
</Style>
</Styles>
@@ -32,6 +32,7 @@
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/UserControl.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/Window.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/Button.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/HyperlinkButton.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/RepeatButton.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/ToggleButton.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/RadioButton.axaml" />
@@ -60,4 +61,6 @@
</ResourceDictionary>
</Styles.Resources>
<StyleInclude Source="avares://HandyControl/Themes/Styles/HyperlinkButton.classes.axaml" />
</Styles>