Skip to content

Commit

Permalink
chore: add avalonia DashedButton demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Aug 7, 2024
1 parent a6c4f7b commit ed5ce0a
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,62 @@
Theme="{StaticResource ButtonDanger}" />
</StackPanel>
</WrapPanel>
<WrapPanel>
<StackPanel>
<Button Content="default"
Margin="5"
Theme="{StaticResource ButtonDashed}" />
<Button IsEnabled="False"
Content="default"
Margin="5"
Theme="{StaticResource ButtonDashed}" />
</StackPanel>
<StackPanel>
<Button Content="primary"
Margin="5"
Theme="{StaticResource ButtonDashedPrimary}" />
<Button IsEnabled="False"
Content="primary"
Margin="5"
Theme="{StaticResource ButtonDashedPrimary}" />
</StackPanel>
<StackPanel>
<Button Content="success"
Margin="5"
Theme="{StaticResource ButtonDashedSuccess}" />
<Button IsEnabled="False"
Content="success"
Margin="5"
Theme="{StaticResource ButtonDashedSuccess}" />
</StackPanel>
<StackPanel>
<Button Content="info"
Margin="5"
Theme="{StaticResource ButtonDashedInfo}" />
<Button IsEnabled="False"
Content="info"
Margin="5"
Theme="{StaticResource ButtonDashedInfo}" />
</StackPanel>
<StackPanel>
<Button Content="warning"
Margin="5"
Theme="{StaticResource ButtonDashedWarning}" />
<Button IsEnabled="False"
Content="warning"
Margin="5"
Theme="{StaticResource ButtonDashedWarning}" />
</StackPanel>
<StackPanel>
<Button Content="danger"
Margin="5"
Theme="{StaticResource ButtonDashedDanger}" />
<Button IsEnabled="False"
Content="danger"
Margin="5"
Theme="{StaticResource ButtonDashedDanger}" />
</StackPanel>
</WrapPanel>
</hc:UniformSpacingPanel>
</hc:UniformSpacingPanel>
</ScrollViewer>
Expand Down
98 changes: 92 additions & 6 deletions src/Avalonia/HandyControl_Avalonia/Themes/Styles/Button.axaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol">
<ControlTheme x:Key="ButtonBaseStyle"
TargetType="Button">
<Setter Property="Height"
Expand Down Expand Up @@ -40,34 +41,60 @@
</ControlTemplate>
</Setter>

<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:pointerover">
<Setter Property="Opacity"
Value="0.9" />
</Style>

<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:pressed">
<Setter Property="Opacity"
Value="0.6" />
</Style>

<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
</ControlTheme>

<ControlTheme x:Key="ButtonDashedBaseStyle"
BasedOn="{StaticResource ButtonBaseStyle}"
TargetType="Button">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<hc:DashedBorder BorderDashArray="3,2"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="{TemplateBinding CornerRadius}">
<ContentPresenter x:Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Padding="{TemplateBinding Padding}"
RecognizesAccessKey="True"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</hc:DashedBorder>
</ControlTemplate>
</Setter.Value>
</Setter>
</ControlTheme>

<ControlTheme x:Key="ButtonDefault"
BasedOn="{StaticResource ButtonBaseStyle}"
TargetType="Button">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" />

<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:pointerover">
<Setter Property="Background"
Value="{DynamicResource SecondaryRegionBrush}" />
</Style>

<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:pressed">
<Setter Property="Background"
Value="{DynamicResource BorderBrush}" />
</Style>
Expand Down Expand Up @@ -121,4 +148,63 @@
<Setter Property="BorderBrush"
Value="{DynamicResource DangerBrush}" />
</ControlTheme>

<ControlTheme x:Key="ButtonDashed"
BasedOn="{StaticResource ButtonDashedBaseStyle}"
TargetType="Button">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" />

<Style Selector="^:pointerover">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource PrimaryBrush}" />
</Style>
</ControlTheme>

<ControlTheme x:Key="ButtonDashedPrimary"
BasedOn="{StaticResource ButtonDashedBaseStyle}"
TargetType="Button">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource PrimaryBrush}" />
</ControlTheme>

<ControlTheme x:Key="ButtonDashedSuccess"
BasedOn="{StaticResource ButtonDashedBaseStyle}"
TargetType="Button">
<Setter Property="Foreground"
Value="{DynamicResource SuccessBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource SuccessBrush}" />
</ControlTheme>

<ControlTheme x:Key="ButtonDashedInfo"
BasedOn="{StaticResource ButtonDashedBaseStyle}"
TargetType="Button">
<Setter Property="Foreground"
Value="{DynamicResource InfoBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource InfoBrush}" />
</ControlTheme>

<ControlTheme x:Key="ButtonDashedWarning"
BasedOn="{StaticResource ButtonDashedBaseStyle}"
TargetType="Button">
<Setter Property="Foreground"
Value="{DynamicResource WarningBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource WarningBrush}" />
</ControlTheme>

<ControlTheme x:Key="ButtonDashedDanger"
BasedOn="{StaticResource ButtonDashedBaseStyle}"
TargetType="Button">
<Setter Property="Foreground"
Value="{DynamicResource DangerBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource DangerBrush}" />
</ControlTheme>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</ControlTemplate>
</Setter>

<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@
</ControlTemplate>
</Setter>

<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:pointerover">
<Setter Property="Opacity"
Value="0.9" />
</Style>

<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:pressed">
<Setter Property="Opacity"
Value="0.6" />
</Style>

<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
Expand All @@ -62,12 +62,12 @@
<Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" />

<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:pointerover">
<Setter Property="Background"
Value="{DynamicResource SecondaryRegionBrush}" />
</Style>

<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:pressed">
<Setter Property="Background"
Value="{DynamicResource BorderBrush}" />
</Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
</ControlTemplate>
</Setter>

<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>

<Style Selector="^:selected /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^:selected">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryBrush}" />
</Style>
Expand Down

0 comments on commit ed5ce0a

Please sign in to comment.