ProgressBar.xaml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <ResourceDictionary xmlns="https://github.com/avaloniaui"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls">
  4. <Design.PreviewWith>
  5. <Border Padding="20">
  6. <StackPanel Spacing="10">
  7. <ProgressBar VerticalAlignment="Center" IsIndeterminate="True" />
  8. <ProgressBar VerticalAlignment="Center" Value="5" Maximum="10" />
  9. <ProgressBar VerticalAlignment="Center" Value="50" />
  10. <ProgressBar VerticalAlignment="Center" Value="50" Minimum="25" Maximum="75" />
  11. <ProgressBar HorizontalAlignment="Left" IsIndeterminate="True" Orientation="Vertical" />
  12. </StackPanel>
  13. </Border>
  14. </Design.PreviewWith>
  15. <converters:StringFormatConverter x:Key="StringFormatConverter" />
  16. <ControlTheme x:Key="{x:Type ProgressBar}"
  17. TargetType="ProgressBar">
  18. <Setter Property="Background" Value="{DynamicResource ThemeAccentBrush4}" />
  19. <Setter Property="Foreground" Value="{DynamicResource ThemeAccentBrush}" />
  20. <Setter Property="Template">
  21. <ControlTemplate TargetType="ProgressBar">
  22. <Grid>
  23. <Border Background="{TemplateBinding Background}"
  24. BorderBrush="{TemplateBinding BorderBrush}"
  25. BorderThickness="{TemplateBinding BorderThickness}"
  26. CornerRadius="{TemplateBinding CornerRadius}">
  27. <Panel>
  28. <Border Name="PART_Indicator"
  29. Background="{TemplateBinding Foreground}"
  30. IsVisible="{Binding !IsIndeterminate, RelativeSource={RelativeSource TemplatedParent}}" />
  31. <Border Name="PART_IndeterminateIndicator"
  32. Background="{TemplateBinding Foreground}"
  33. IsVisible="{Binding IsIndeterminate, RelativeSource={RelativeSource TemplatedParent}}" />
  34. </Panel>
  35. </Border>
  36. <LayoutTransformControl Name="PART_LayoutTransformControl"
  37. HorizontalAlignment="Center"
  38. VerticalAlignment="Center"
  39. IsVisible="{Binding ShowProgressText, RelativeSource={RelativeSource TemplatedParent}}">
  40. <TextBlock Foreground="{DynamicResource ThemeForegroundBrush}">
  41. <TextBlock.Text>
  42. <MultiBinding Converter="{StaticResource StringFormatConverter}">
  43. <TemplateBinding Property="ProgressTextFormat" />
  44. <Binding Path="Value"
  45. RelativeSource="{RelativeSource TemplatedParent}" />
  46. <TemplateBinding Property="Percentage" />
  47. <TemplateBinding Property="Minimum" />
  48. <TemplateBinding Property="Maximum" />
  49. </MultiBinding>
  50. </TextBlock.Text>
  51. </TextBlock>
  52. </LayoutTransformControl>
  53. </Grid>
  54. </ControlTemplate>
  55. </Setter>
  56. <Style Selector="^:horizontal /template/ Border#PART_Indicator">
  57. <Setter Property="HorizontalAlignment" Value="Left" />
  58. <Setter Property="VerticalAlignment" Value="Stretch" />
  59. </Style>
  60. <Style Selector="^:vertical /template/ Border#PART_Indicator">
  61. <Setter Property="HorizontalAlignment" Value="Stretch" />
  62. <Setter Property="VerticalAlignment" Value="Bottom" />
  63. </Style>
  64. <Style Selector="^:horizontal">
  65. <Setter Property="MinWidth" Value="200" />
  66. <Setter Property="MinHeight" Value="16" />
  67. </Style>
  68. <Style Selector="^:vertical">
  69. <Setter Property="MinWidth" Value="16" />
  70. <Setter Property="MinHeight" Value="200" />
  71. </Style>
  72. <Style Selector="^:vertical /template/ LayoutTransformControl#PART_LayoutTransformControl">
  73. <Setter Property="LayoutTransform">
  74. <Setter.Value>
  75. <RotateTransform Angle="90" />
  76. </Setter.Value>
  77. </Setter>
  78. </Style>
  79. <Style Selector="^:horizontal:indeterminate /template/ Border#PART_IndeterminateIndicator">
  80. <Style.Animations>
  81. <Animation Easing="LinearEasing"
  82. IterationCount="Infinite"
  83. Duration="0:0:3">
  84. <KeyFrame Cue="0%">
  85. <Setter Property="TranslateTransform.X" Value="{Binding IndeterminateStartingOffset, RelativeSource={RelativeSource TemplatedParent}}" />
  86. </KeyFrame>
  87. <KeyFrame Cue="100%">
  88. <Setter Property="TranslateTransform.X" Value="{Binding IndeterminateEndingOffset, RelativeSource={RelativeSource TemplatedParent}}" />
  89. </KeyFrame>
  90. </Animation>
  91. </Style.Animations>
  92. <Setter Property="Width" Value="{Binding TemplateProperties.ContainerWidth, RelativeSource={RelativeSource TemplatedParent}}" />
  93. </Style>
  94. <Style Selector="^:vertical:indeterminate /template/ Border#PART_IndeterminateIndicator">
  95. <Style.Animations>
  96. <Animation Easing="LinearEasing"
  97. IterationCount="Infinite"
  98. Duration="0:0:3">
  99. <KeyFrame Cue="0%">
  100. <Setter Property="TranslateTransform.Y" Value="{Binding IndeterminateStartingOffset, RelativeSource={RelativeSource TemplatedParent}}" />
  101. </KeyFrame>
  102. <KeyFrame Cue="100%">
  103. <Setter Property="TranslateTransform.Y" Value="{Binding IndeterminateEndingOffset, RelativeSource={RelativeSource TemplatedParent}}" />
  104. </KeyFrame>
  105. </Animation>
  106. </Style.Animations>
  107. <Setter Property="Height" Value="{Binding TemplateProperties.ContainerWidth, RelativeSource={RelativeSource TemplatedParent}}" />
  108. </Style>
  109. </ControlTheme>
  110. </ResourceDictionary>