chore: add avalonia DashedButton demo.

This commit is contained in:
NaBian 2024-08-07 22:27:27 +08:00
parent a6c4f7b2f3
commit ed5ce0a913
5 changed files with 156 additions and 14 deletions

View File

@ -63,6 +63,62 @@
Theme="{StaticResource ButtonDanger}" /> Theme="{StaticResource ButtonDanger}" />
</StackPanel> </StackPanel>
</WrapPanel> </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>
</hc:UniformSpacingPanel> </hc:UniformSpacingPanel>
</ScrollViewer> </ScrollViewer>

View File

@ -1,5 +1,6 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" <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" <ControlTheme x:Key="ButtonBaseStyle"
TargetType="Button"> TargetType="Button">
<Setter Property="Height" <Setter Property="Height"
@ -40,34 +41,60 @@
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:pointerover">
<Setter Property="Opacity" <Setter Property="Opacity"
Value="0.9" /> Value="0.9" />
</Style> </Style>
<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:pressed">
<Setter Property="Opacity" <Setter Property="Opacity"
Value="0.6" /> Value="0.6" />
</Style> </Style>
<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:disabled">
<Setter Property="Opacity" <Setter Property="Opacity"
Value="0.4" /> Value="0.4" />
</Style> </Style>
</ControlTheme> </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" <ControlTheme x:Key="ButtonDefault"
BasedOn="{StaticResource ButtonBaseStyle}" BasedOn="{StaticResource ButtonBaseStyle}"
TargetType="Button"> TargetType="Button">
<Setter Property="Foreground" <Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" /> Value="{DynamicResource PrimaryTextBrush}" />
<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:pointerover">
<Setter Property="Background" <Setter Property="Background"
Value="{DynamicResource SecondaryRegionBrush}" /> Value="{DynamicResource SecondaryRegionBrush}" />
</Style> </Style>
<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:pressed">
<Setter Property="Background" <Setter Property="Background"
Value="{DynamicResource BorderBrush}" /> Value="{DynamicResource BorderBrush}" />
</Style> </Style>
@ -121,4 +148,63 @@
<Setter Property="BorderBrush" <Setter Property="BorderBrush"
Value="{DynamicResource DangerBrush}" /> Value="{DynamicResource DangerBrush}" />
</ControlTheme> </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> </ResourceDictionary>

View File

@ -38,7 +38,7 @@
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:disabled">
<Setter Property="Opacity" <Setter Property="Opacity"
Value="0.4" /> Value="0.4" />
</Style> </Style>

View File

@ -40,17 +40,17 @@
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:pointerover">
<Setter Property="Opacity" <Setter Property="Opacity"
Value="0.9" /> Value="0.9" />
</Style> </Style>
<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:pressed">
<Setter Property="Opacity" <Setter Property="Opacity"
Value="0.6" /> Value="0.6" />
</Style> </Style>
<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:disabled">
<Setter Property="Opacity" <Setter Property="Opacity"
Value="0.4" /> Value="0.4" />
</Style> </Style>
@ -62,12 +62,12 @@
<Setter Property="Foreground" <Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" /> Value="{DynamicResource PrimaryTextBrush}" />
<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:pointerover">
<Setter Property="Background" <Setter Property="Background"
Value="{DynamicResource SecondaryRegionBrush}" /> Value="{DynamicResource SecondaryRegionBrush}" />
</Style> </Style>
<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:pressed">
<Setter Property="Background" <Setter Property="Background"
Value="{DynamicResource BorderBrush}" /> Value="{DynamicResource BorderBrush}" />
</Style> </Style>

View File

@ -38,12 +38,12 @@
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:disabled">
<Setter Property="Opacity" <Setter Property="Opacity"
Value="0.4" /> Value="0.4" />
</Style> </Style>
<Style Selector="^:selected /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:selected">
<Setter Property="Foreground" <Setter Property="Foreground"
Value="{DynamicResource PrimaryBrush}" /> Value="{DynamicResource PrimaryBrush}" />
</Style> </Style>