feat: Add ButtonGroup control and styles.

This commit is contained in:
NaBian committed 2026-06-13 19:21:15 +08:00
1 parent 2ac7dfaf96
commit ee5c47a7cd
9 files changed
+690 -36

No files matched your search

@@ -769,4 +769,130 @@
<Setter Property="Width"
Value="20" />
</ControlTheme>
<ControlTheme x:Key="ToggleButtonGroupItemBaseStyle"
TargetType="ToggleButton">
<Setter Property="Background"
Value="{DynamicResource RegionBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource BorderBrush}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="VerticalAlignment"
Value="Center" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="hc:BorderElement.CornerRadius"
Value="0" />
<Setter Property="CornerRadius"
Value="{Binding $self.(hc:BorderElement.CornerRadius)}" />
<Setter Property="Height"
Value="{StaticResource DefaultControlHeight}" />
<Setter Property="Padding"
Value="10,0" />
<Setter Property="Template">
<ControlTemplate TargetType="ToggleButton">
<Border x:Name="BorderRoot"
CornerRadius="{TemplateBinding CornerRadius}"
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}">
<Path x:Name="PathMain"
Width="{TemplateBinding hc:IconElement.Width}"
Height="{TemplateBinding hc:IconElement.Height}"
Fill="{TemplateBinding Foreground}"
IsVisible="{Binding Path=(hc:IconElement.Geometry), RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static ObjectConverters.IsNotNull}}"
Stretch="Uniform"
Data="{TemplateBinding hc:IconElement.Geometry}" />
<ContentPresenter x:Name="contentPresenter"
RecognizesAccessKey="True"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
IsVisible="{Binding $self.Content, Converter={x:Static ObjectConverters.IsNotNull}}"
Margin="{Binding Path=(hc:IconElement.Geometry), RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource GeometrySpacingConverter}, ConverterParameter='6,0,0,0'}" />
</StackPanel>
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover">
<Setter Property="Background"
Value="{DynamicResource SecondaryRegionBrush}" />
<Style Selector="^ /template/ ContentPresenter#contentPresenter">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryBrush}" />
</Style>
</Style>
<Style Selector="^:pressed">
<Setter Property="Background"
Value="{DynamicResource BorderBrush}" />
</Style>
<Style Selector="^:checked">
<Setter Property="ZIndex"
Value="2147483647" />
<Style Selector="^ /template/ Border#BorderRoot">
<Setter Property="BorderBrush"
Value="{Binding $parent[ToggleButton].(hc:VisualElement.HighlightBorderBrush)}" />
<Setter Property="Background"
Value="{Binding $parent[ToggleButton].(hc:VisualElement.HighlightBackground)}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#contentPresenter">
<Setter Property="Foreground"
Value="{Binding $parent[ToggleButton].(hc:VisualElement.HighlightForeground)}" />
</Style>
</Style>
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
</ControlTheme>
<ControlTheme x:Key="ToggleButtonGroupItemDefault"
BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}"
TargetType="ToggleButton" />
<ControlTheme x:Key="ToggleButtonGroupItemHorizontalFirst"
BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}"
TargetType="ToggleButton">
<Setter Property="hc:BorderElement.CornerRadius"
Value="4,0,0,4" />
</ControlTheme>
<ControlTheme x:Key="ToggleButtonGroupItemHorizontalLast"
BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}"
TargetType="ToggleButton">
<Setter Property="hc:BorderElement.CornerRadius"
Value="0,4,4,0" />
</ControlTheme>
<ControlTheme x:Key="ToggleButtonGroupItemSingle"
BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}"
TargetType="ToggleButton">
<Setter Property="hc:BorderElement.CornerRadius"
Value="{StaticResource DefaultCornerRadius}" />
</ControlTheme>
<ControlTheme x:Key="ToggleButtonGroupItemVerticalFirst"
BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}"
TargetType="ToggleButton">
<Setter Property="hc:BorderElement.CornerRadius"
Value="4,4,0,0" />
</ControlTheme>
<ControlTheme x:Key="ToggleButtonGroupItemVerticalLast"
BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}"
TargetType="ToggleButton">
<Setter Property="hc:BorderElement.CornerRadius"
Value="0,0,4,4" />
</ControlTheme>
</ResourceDictionary>