refactor: refactor ProgressBar styles for improved layout and animation.

This commit is contained in:
Zhang Dian
2026-03-04 14:50:36 +08:00
parent de3ffc97b6
commit f08a26bc60

View File

@@ -4,87 +4,19 @@
xmlns:semi="https://irihi.tech/semi" xmlns:semi="https://irihi.tech/semi"
xmlns:converters="using:Avalonia.Controls.Converters"> xmlns:converters="using:Avalonia.Controls.Converters">
<Design.PreviewWith> <Design.PreviewWith>
<StackPanel Margin="20" Spacing="20"> <StackPanel Width="200" Margin="20" Spacing="20">
<ProgressBar <ProgressBar ShowProgressText="True" Value="20" />
Width="200" <ProgressBar IsIndeterminate="True" ShowProgressText="True" Value="20" />
Maximum="100" <ProgressBar Classes="Left" IsIndeterminate="True" ShowProgressText="True" Value="20" />
Minimum="0" <ProgressBar Classes="Left" ShowProgressText="True" Value="20" />
ShowProgressText="True" <ProgressBar Classes="Right" ShowProgressText="True" Value="20" />
Value="20" /> <StackPanel Orientation="Horizontal" Spacing="20">
<ProgressBar <ProgressBar Classes="Top" Orientation="Vertical" ShowProgressText="True" Value="20" />
Width="200" <ProgressBar Classes="Bottom" Orientation="Vertical" ShowProgressText="True" Value="20" />
IsIndeterminate="True" <ProgressBar Orientation="Vertical" ShowProgressText="True" Value="20" />
Maximum="100" <ProgressBar Classes="Top" Orientation="Vertical" ShowProgressText="False" Value="20" />
Minimum="0" <ProgressBar IsIndeterminate="True" Orientation="Vertical" ShowProgressText="True" Value="20" />
ShowProgressText="True" <ProgressBar IsIndeterminate="True" Orientation="Vertical" ShowProgressText="False" Value="20" />
Value="20" />
<ProgressBar
Width="200"
Classes="Left"
IsIndeterminate="True"
Maximum="100"
Minimum="0"
ShowProgressText="True"
Value="20" />
<ProgressBar
Width="200"
Classes="Left"
Maximum="100"
Minimum="0"
ShowProgressText="True"
Value="20" />
<ProgressBar
Width="200"
Classes="Right"
Maximum="100"
Minimum="0"
ShowProgressText="True"
Value="20" />
<StackPanel
HorizontalAlignment="Left"
Orientation="Horizontal"
Spacing="20">
<ProgressBar
Classes="Left"
Maximum="100"
Minimum="0"
Orientation="Vertical"
ShowProgressText="True"
Value="20" />
<ProgressBar
Classes="Right"
Maximum="100"
Minimum="0"
Orientation="Vertical"
ShowProgressText="True"
Value="20" />
<ProgressBar
Maximum="100"
Minimum="0"
Orientation="Vertical"
ShowProgressText="True"
Value="20" />
<ProgressBar
Classes="Left"
Maximum="100"
Minimum="0"
Orientation="Vertical"
ShowProgressText="False"
Value="20" />
<ProgressBar
IsIndeterminate="True"
Maximum="100"
Minimum="0"
Orientation="Vertical"
ShowProgressText="True"
Value="20" />
<ProgressBar
IsIndeterminate="True"
Maximum="100"
Minimum="0"
Orientation="Vertical"
ShowProgressText="False"
Value="20" />
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</Design.PreviewWith> </Design.PreviewWith>
@@ -115,7 +47,7 @@
<Panel Name="DeterminateRoot" Opacity="1"> <Panel Name="DeterminateRoot" Opacity="1">
<Panel.Transitions> <Panel.Transitions>
<Transitions> <Transitions>
<DoubleTransition Property="Opacity" Duration="0:0:0.197" /> <DoubleTransition Property="Opacity" Duration="0:0:0.2" />
</Transitions> </Transitions>
</Panel.Transitions> </Panel.Transitions>
<Border <Border
@@ -127,7 +59,7 @@
<Panel Name="IndeterminateRoot" Opacity="0"> <Panel Name="IndeterminateRoot" Opacity="0">
<Panel.Transitions> <Panel.Transitions>
<Transitions> <Transitions>
<DoubleTransition Property="Opacity" Duration="0:0:0.197" /> <DoubleTransition Property="Opacity" Duration="0:0:0.2" />
</Transitions> </Transitions>
</Panel.Transitions> </Panel.Transitions>
<Border <Border
@@ -158,7 +90,7 @@
<TextBlock.Text> <TextBlock.Text>
<MultiBinding Converter="{StaticResource StringFormatConverter}"> <MultiBinding Converter="{StaticResource StringFormatConverter}">
<TemplateBinding Property="ProgressTextFormat" /> <TemplateBinding Property="ProgressTextFormat" />
<Binding Path="Value" RelativeSource="{RelativeSource TemplatedParent}" /> <TemplateBinding Property="Value" />
<TemplateBinding Property="Percentage" /> <TemplateBinding Property="Percentage" />
<TemplateBinding Property="Minimum" /> <TemplateBinding Property="Minimum" />
<TemplateBinding Property="Maximum" /> <TemplateBinding Property="Maximum" />
@@ -191,149 +123,154 @@
<Style Selector="^.Error"> <Style Selector="^.Error">
<Setter Property="Foreground" Value="{DynamicResource ProgressBarErrorForeground}" /> <Setter Property="Foreground" Value="{DynamicResource ProgressBarErrorForeground}" />
</Style> </Style>
<Style Selector="^:horizontal /template/ Border#PART_Indicator">
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Stretch" />
</Style>
<Style Selector="^:vertical /template/ Border#PART_Indicator">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Top" />
</Style>
<Style Selector="^:horizontal"> <Style Selector="^:horizontal">
<Setter Property="MinWidth" Value="200" /> <Setter Property="MinWidth" Value="200" />
<Setter Property="MinHeight" Value="4" /> <Setter Property="MinHeight" Value="4" />
<Style Selector="^ /template/ Border#PART_Indicator">
<Setter Property="HorizontalAlignment" Value="Left" />
</Style>
<Style Selector="^ /template/ Border#IndeterminateProgressBarIndicator">
<Setter Property="Width" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerWidth}" />
</Style>
<Style Selector="^ /template/ Border#IndeterminateProgressBarIndicator2">
<Setter Property="Width" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2Width}" />
</Style>
<Style Selector="^.Left,^.Top">
<Style Selector="^ /template/ LayoutTransformControl#PART_LayoutTransformControl">
<Setter Property="Grid.Column" Value="0" />
<Setter Property="Grid.Row" Value="1" />
<Setter Property="Margin" Value="0 0 16 0" />
<Setter Property="MinWidth" Value="45" />
</Style>
<Style Selector="^ /template/ Border#ProgressBarRoot">
<Setter Property="MinHeight" Value="4" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</Style>
<Style Selector="^.Right,^.Bottom">
<Style Selector="^ /template/ LayoutTransformControl#PART_LayoutTransformControl">
<Setter Property="Grid.Column" Value="2" />
<Setter Property="Grid.Row" Value="1" />
<Setter Property="Margin" Value="16 0 0 0" />
<Setter Property="MinWidth" Value="45" />
</Style>
<Style Selector="^ /template/ Border#ProgressBarRoot">
<Setter Property="MinHeight" Value="4" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</Style>
</Style> </Style>
<Style Selector="^:vertical"> <Style Selector="^:vertical">
<Style Selector="^ /template/ LayoutTransformControl#PART_LayoutTransformControl">
<Setter Property="LayoutTransform">
<RotateTransform Angle="90" />
</Setter>
</Style>
<Setter Property="MinWidth" Value="4" /> <Setter Property="MinWidth" Value="4" />
<Setter Property="MinHeight" Value="200" /> <Setter Property="MinHeight" Value="200" />
</Style> <Style Selector="^ /template/ Border#PART_Indicator">
<Style Selector="^:vertical /template/ LayoutTransformControl#PART_LayoutTransformControl"> <Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="LayoutTransform">
<RotateTransform Angle="90" />
</Setter>
</Style>
<Style Selector="^:indeterminate /template/ Panel#DeterminateRoot">
<Setter Property="Opacity" Value="0" />
</Style>
<Style Selector="^:indeterminate /template/ Panel#IndeterminateRoot">
<Setter Property="Opacity" Value="1" />
</Style>
<Style Selector="^:horizontal:indeterminate /template/ Border#IndeterminateProgressBarIndicator">
<Style.Animations>
<Animation IterationCount="Infinite" Duration="0:0:2">
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:1.5">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationEndPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:2">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationEndPosition}" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
<Style Selector="^:horizontal:indeterminate /template/ Border#IndeterminateProgressBarIndicator2">
<Style.Animations>
<Animation IterationCount="Infinite" Duration="0:0:2">
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0.75">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:2">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationEndPosition}" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
<Style Selector="^:vertical:indeterminate /template/ Border#IndeterminateProgressBarIndicator">
<Style.Animations>
<Animation IterationCount="Infinite" Duration="0:0:2">
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:1.5">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationEndPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:2">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationEndPosition}" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
<Style Selector="^:vertical:indeterminate /template/ Border#IndeterminateProgressBarIndicator2">
<Style.Animations>
<Animation IterationCount="Infinite" Duration="0:0:2">
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0.75">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:2">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationEndPosition}" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
<Style Selector="^:horizontal /template/ Border#IndeterminateProgressBarIndicator">
<Setter Property="Width" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerWidth}" />
</Style>
<Style Selector="^:horizontal /template/ Border#IndeterminateProgressBarIndicator2">
<Setter Property="Width" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2Width}" />
</Style>
<Style Selector="^:vertical /template/ Border#IndeterminateProgressBarIndicator">
<Setter Property="Height" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerWidth}" />
</Style>
<Style Selector="^:vertical /template/ Border#IndeterminateProgressBarIndicator2">
<Setter Property="Height" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2Width}" />
</Style>
<Style Selector="^.Left">
<Style Selector="^:horizontal /template/ LayoutTransformControl#PART_LayoutTransformControl">
<Setter Property="Grid.Column" Value="0" />
<Setter Property="Grid.Row" Value="1" />
<Setter Property="Margin" Value="4 0" />
</Style> </Style>
<Style Selector="^:vertical /template/ LayoutTransformControl#PART_LayoutTransformControl"> <Style Selector="^ /template/ Border#IndeterminateProgressBarIndicator">
<Setter Property="Grid.Column" Value="1" /> <Setter Property="Height" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerWidth}" />
<Setter Property="Grid.Row" Value="0" />
<Setter Property="Margin" Value="0 4" />
</Style> </Style>
<Style Selector="^:horizontal /template/ Border#ProgressBarRoot"> <Style Selector="^ /template/ Border#IndeterminateProgressBarIndicator2">
<Setter Property="MinHeight" Value="4" /> <Setter Property="Height" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2Width}" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style> </Style>
<Style Selector="^:vertical /template/ Border#ProgressBarRoot"> <Style Selector="^.Left,^.Top">
<Setter Property="MinWidth" Value="4" /> <Style Selector="^ /template/ LayoutTransformControl#PART_LayoutTransformControl">
<Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="Grid.Column" Value="1" />
<Setter Property="Grid.Row" Value="0" />
<Setter Property="Margin" Value="0 0 0 16" />
</Style>
<Style Selector="^ /template/ Border#ProgressBarRoot">
<Setter Property="MinWidth" Value="4" />
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
</Style> </Style>
<Style Selector="^ /template/ TextBlock#PART_ProgressText"> <Style Selector="^.Right,^.Bottom">
<Setter Property="Foreground" Value="{DynamicResource ProgressBarOuterTextForeground}" /> <Style Selector="^ /template/ LayoutTransformControl#PART_LayoutTransformControl">
<Setter Property="Grid.Column" Value="1" />
<Setter Property="Grid.Row" Value="2" />
<Setter Property="Margin" Value="0 16 0 0" />
<Setter Property="MinHeight" Value="45" />
</Style>
<Style Selector="^ /template/ Border#ProgressBarRoot">
<Setter Property="MinWidth" Value="4" />
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
</Style> </Style>
</Style> </Style>
<Style Selector="^.Right">
<Style Selector="^:horizontal /template/ LayoutTransformControl#PART_LayoutTransformControl"> <Style Selector="^:indeterminate">
<Setter Property="Grid.Column" Value="2" /> <Style Selector="^ /template/ Panel#DeterminateRoot">
<Setter Property="Grid.Row" Value="1" /> <Setter Property="Opacity" Value="0" />
<Setter Property="Margin" Value="4 0" />
</Style> </Style>
<Style Selector="^:vertical /template/ LayoutTransformControl#PART_LayoutTransformControl"> <Style Selector="^ /template/ Panel#IndeterminateRoot">
<Setter Property="Grid.Column" Value="1" /> <Setter Property="Opacity" Value="1" />
<Setter Property="Grid.Row" Value="2" />
<Setter Property="Margin" Value="0 4" />
</Style> </Style>
<Style Selector="^:horizontal /template/ Border#ProgressBarRoot"> <Style Selector="^:horizontal /template/ Border#IndeterminateProgressBarIndicator">
<Setter Property="MinHeight" Value="4" /> <Style.Animations>
<Setter Property="VerticalAlignment" Value="Center" /> <Animation IterationCount="Infinite" Duration="0:0:2">
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:1.5">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationEndPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:2">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationEndPosition}" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style> </Style>
<Style Selector="^:vertical /template/ Border#ProgressBarRoot"> <Style Selector="^:horizontal /template/ Border#IndeterminateProgressBarIndicator2">
<Setter Property="MinWidth" Value="4" /> <Style.Animations>
<Setter Property="HorizontalAlignment" Value="Center" /> <Animation IterationCount="Infinite" Duration="0:0:2">
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0.75">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:2">
<Setter Property="TranslateTransform.X" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationEndPosition}" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style> </Style>
<Style Selector="^ /template/ TextBlock#PART_ProgressText"> <Style Selector="^:vertical /template/ Border#IndeterminateProgressBarIndicator">
<Setter Property="Foreground" Value="{DynamicResource ProgressBarOuterTextForeground}" /> <Style.Animations>
<Animation IterationCount="Infinite" Duration="0:0:2">
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:1.5">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationEndPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:2">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.ContainerAnimationEndPosition}" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
<Style Selector="^:vertical /template/ Border#IndeterminateProgressBarIndicator2">
<Style.Animations>
<Animation IterationCount="Infinite" Duration="0:0:2">
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:0.75">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationStartPosition}" />
</KeyFrame>
<KeyFrame KeySpline="0.4,0,0.6,1" KeyTime="0:0:2">
<Setter Property="TranslateTransform.Y" Value="{Binding $parent[ProgressBar].TemplateSettings.Container2AnimationEndPosition}" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style> </Style>
</Style> </Style>
</ControlTheme> </ControlTheme>