Files
Semi.Avalonia/src/Semi.Avalonia/Controls/Expander.axaml
2025-03-06 14:38:50 +08:00

152 lines
8.4 KiB
XML

<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:CompileBindings="True">
<Design.PreviewWith>
<StackPanel Margin="20" Spacing="20">
<TextBox>Hello</TextBox>
<Expander Header="Hello">Content</Expander>
</StackPanel>
</Design.PreviewWith>
<ControlTheme x:Key="ExpanderHeaderToggleButtonTheme" TargetType="ToggleButton">
<Setter Property="Template">
<ControlTemplate TargetType="ToggleButton">
<ContentPresenter
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
Content="{TemplateBinding Content}" />
</ControlTemplate>
</Setter>
</ControlTheme>
<ControlTheme x:Key="{x:Type Expander}" TargetType="Expander">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="{DynamicResource ExpanderSeparatorBorderBrush}" />
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Template">
<ControlTemplate TargetType="Expander">
<DockPanel>
<LayoutTransformControl Name="ExpanderHeaderLayoutContainer" Margin="{DynamicResource ExpanderHeaderMargin}">
<ToggleButton
Name="ExpanderHeader"
Padding="{DynamicResource ExpanderHeaderPadding}"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Background="{DynamicResource ExpanderHeaderDefaultBackground}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
IsChecked="{TemplateBinding IsExpanded, Mode=TwoWay}"
IsEnabled="{TemplateBinding IsEnabled}"
TextElement.FontWeight="{DynamicResource ExpanderHeaderFontWeight}"
TextElement.Foreground="{DynamicResource ExpanderHeaderForeground}"
Theme="{StaticResource ExpanderHeaderToggleButtonTheme}">
<Grid Background="Transparent" ColumnDefinitions="*, Auto">
<ContentPresenter
Grid.Column="0"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}" />
<PathIcon
Name="PART_PathIcon"
Grid.Column="1"
Theme="{DynamicResource InnerPathIcon}"
Margin="{DynamicResource ExpanderIconMargin}"
Data="{DynamicResource ExpanderIcon}">
<PathIcon.Transitions>
<Transitions>
<TransformOperationsTransition Property="RenderTransform" Duration="0.1" />
</Transitions>
</PathIcon.Transitions>
</PathIcon>
</Grid>
</ToggleButton>
</LayoutTransformControl>
<LayoutTransformControl Name="ExpanderContentLayoutContainer" MinHeight="1">
<Border
Name="ExpanderContent"
MinHeight="2"
BorderBrush="{DynamicResource ExpanderSeparatorBorderBrush}"
BorderThickness="0,0,0,1">
<ContentPresenter
Name="PART_ContentPresenter"
Margin="{DynamicResource ExpanderContentMargin}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Foreground="{DynamicResource ExpanderContentForeground}"
IsVisible="{TemplateBinding IsExpanded, Mode=TwoWay}" />
</Border>
</LayoutTransformControl>
</DockPanel>
</ControlTemplate>
</Setter>
<Style Selector="^:expanded /template/ PathIcon#PART_PathIcon">
<Setter Property="RenderTransform" Value="rotate(180deg)" />
</Style>
<Style Selector="^:right">
<Style Selector="^ /template/ LayoutTransformControl#ExpanderHeaderLayoutContainer">
<Setter Property="LayoutTransform">
<RotateTransform Angle="-90" />
</Setter>
<Setter Property="VerticalAlignment" Value="Stretch" />
</Style>
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Stretch" />
</Style>
<Style Selector="^:left">
<Style Selector="^ /template/ LayoutTransformControl#ExpanderHeaderLayoutContainer">
<Setter Property="LayoutTransform">
<RotateTransform Angle="90" />
</Setter>
<Setter Property="VerticalAlignment" Value="Stretch" />
</Style>
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
</Style>
<Style Selector="^:left /template/ LayoutTransformControl#ExpanderHeaderLayoutContainer">
<Setter Property="DockPanel.Dock" Value="Right" />
</Style>
<Style Selector="^:up /template/ LayoutTransformControl#ExpanderHeaderLayoutContainer">
<Setter Property="DockPanel.Dock" Value="Bottom" />
</Style>
<Style Selector="^:right /template/ LayoutTransformControl#ExpanderHeaderLayoutContainer">
<Setter Property="DockPanel.Dock" Value="Left" />
</Style>
<Style Selector="^:down /template/ LayoutTransformControl#ExpanderHeaderLayoutContainer">
<Setter Property="DockPanel.Dock" Value="Top" />
</Style>
<Style Selector="^:left /template/ Border#ExpanderContent">
<Setter Property="MinWidth" Value="2" />
<Setter Property="BorderThickness" Value="{DynamicResource ExpanderLeftContentBorderThickness}" />
</Style>
<Style Selector="^:up /template/ Border#ExpanderContent">
<Setter Property="MinHeight" Value="2" />
<Setter Property="BorderThickness" Value="{DynamicResource ExpanderUpContentBorderThickness}" />
</Style>
<Style Selector="^:right /template/ Border#ExpanderContent">
<Setter Property="MinWidth" Value="2" />
<Setter Property="BorderThickness" Value="{DynamicResource ExpanderRightContentBorderThickness}" />
</Style>
<Style Selector="^:down /template/ Border#ExpanderContent">
<Setter Property="MinHeight" Value="2" />
<Setter Property="BorderThickness" Value="{DynamicResource ExpanderDownContentBorderThickness}" />
</Style>
<Style Selector="^ /template/ ToggleButton#ExpanderHeader:pointerover">
<Setter Property="Background" Value="{DynamicResource ExpanderHeaderHoverBackground}" />
</Style>
<Style Selector="^ /template/ ToggleButton#ExpanderHeader:pressed">
<Setter Property="Background" Value="{DynamicResource ExpanderHeaderPressedBackground}" />
</Style>
<Style Selector="^ /template/ ToggleButton#ExpanderHeader:disabled">
<Setter Property="Foreground" Value="{DynamicResource ExpanderHeaderDisabledForeground}" />
</Style>
</ControlTheme>
</ResourceDictionary>