1
0
Эх сурвалжийг харах

Merge pull request #1425 from ahopper/master

Allow progressbar width and height less than default
Jeremy Koritzinsky 7 жил өмнө
parent
commit
15acecfa52

+ 3 - 23
src/Avalonia.Controls/ProgressBar.cs

@@ -26,12 +26,13 @@ namespace Avalonia.Controls
 
         static ProgressBar()
         {
+            PseudoClass(OrientationProperty, o => o == Avalonia.Controls.Orientation.Vertical, ":vertical");
+            PseudoClass(OrientationProperty, o => o == Avalonia.Controls.Orientation.Horizontal, ":horizontal");
+
             ValueProperty.Changed.AddClassHandler<ProgressBar>(x => x.ValueChanged);
 
             IsIndeterminateProperty.Changed.AddClassHandler<ProgressBar>(
                 (p, e) => { if (p._indicator != null) p.UpdateIsIndeterminate((bool)e.NewValue); });
-            OrientationProperty.Changed.AddClassHandler<ProgressBar>(
-                (p, e) => { if (p._indicator != null) p.UpdateOrientation((Orientation)e.NewValue); });
         }
 
         public bool IsIndeterminate
@@ -59,7 +60,6 @@ namespace Avalonia.Controls
             _indicator = e.NameScope.Get<Border>("PART_Indicator");
 
             UpdateIndicator(Bounds.Size);
-            UpdateOrientation(Orientation);
             UpdateIsIndeterminate(IsIndeterminate);
         }
 
@@ -86,26 +86,6 @@ namespace Avalonia.Controls
             }
         }
 
-        private void UpdateOrientation(Orientation orientation)
-        {
-            if (orientation == Orientation.Horizontal)
-            {
-                MinHeight = 14;
-                MinWidth = 200;
-
-                _indicator.HorizontalAlignment = HorizontalAlignment.Left;
-                _indicator.VerticalAlignment = VerticalAlignment.Stretch;
-            }
-            else
-            {
-                MinHeight = 200;
-                MinWidth = 14;
-
-                _indicator.HorizontalAlignment = HorizontalAlignment.Stretch;
-                _indicator.VerticalAlignment = VerticalAlignment.Bottom;
-            }
-        }
-
         private void UpdateIsIndeterminate(bool isIndeterminate)
         {
             if (isIndeterminate)

+ 38 - 20
src/Avalonia.Themes.Default/ProgressBar.xaml

@@ -1,20 +1,38 @@
-<Style xmlns="https://github.com/avaloniaui" Selector="ProgressBar">
-  <Setter Property="Background" Value="{DynamicResource ThemeAccentBrush4}"/>
-  <Setter Property="Foreground" Value="{DynamicResource ThemeAccentBrush}"/>
-  <Setter Property="Template">
-    <ControlTemplate>
-      <Border Background="{TemplateBinding Background}"
-              BorderBrush="{TemplateBinding BorderBrush}"
-              BorderThickness="{TemplateBinding BorderThickness}">
-        <Grid>
-          <Border Name="PART_Track"
-                  BorderThickness="1"
-                  BorderBrush="{TemplateBinding Background}"/>
-          <Border Name="PART_Indicator"
-                  BorderThickness="1"
-                  Background="{TemplateBinding Foreground}"/>
-        </Grid>
-      </Border>
-    </ControlTemplate>
-  </Setter>
-</Style>
+<Styles xmlns="https://github.com/avaloniaui">
+  <Style Selector="ProgressBar">
+    <Setter Property="Background" Value="{DynamicResource ThemeAccentBrush4}"/>
+    <Setter Property="Foreground" Value="{DynamicResource ThemeAccentBrush}"/> 
+    <Setter Property="Template">
+      <ControlTemplate>
+        <Border Background="{TemplateBinding Background}"
+                BorderBrush="{TemplateBinding BorderBrush}"
+                BorderThickness="{TemplateBinding BorderThickness}">
+          <Grid>
+            <Border Name="PART_Track"
+                    BorderThickness="1"
+                    BorderBrush="{TemplateBinding Background}"/>
+            <Border Name="PART_Indicator"
+                    BorderThickness="1"
+                    Background="{TemplateBinding Foreground}" />
+          </Grid>
+        </Border>
+      </ControlTemplate>
+    </Setter>
+  </Style>
+  <Style Selector="ProgressBar:horizontal /template/ Border#PART_Indicator">
+    <Setter Property="HorizontalAlignment" Value="Left"/>
+    <Setter Property="VerticalAlignment" Value="Stretch"/>
+  </Style>
+  <Style Selector="ProgressBar:vertical /template/ Border#PART_Indicator">
+    <Setter Property="HorizontalAlignment" Value="Stretch"/>
+    <Setter Property="VerticalAlignment" Value="Bottom"/>
+  </Style>
+  <Style Selector="ProgressBar:horizontal">
+    <Setter Property="MinWidth" Value="200"/>
+    <Setter Property="MinHeight" Value="14"/>
+  </Style>
+  <Style Selector="ProgressBar:vertical">
+    <Setter Property="MinWidth" Value="14"/>
+    <Setter Property="MinHeight" Value="200"/>
+  </Style>
+</Styles>