Skip to content

Commit d4aa412

Browse files
committed
fix MetroProgressBar orientation #2148
1 parent 9a862f6 commit d4aa412

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

MahApps.Metro/Controls/MetroProgressBar.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static void ToggleIndeterminate(MetroProgressBar bar, bool oldValue, boo
6868
var resetAction = new Action(() => {
6969
bar.InvalidateMeasure();
7070
bar.InvalidateArrange();
71-
bar.ResetStoryboard(bar.ActualWidth, false);
71+
bar.ResetStoryboard(bar.ActualSize(), false);
7272
});
7373
bar.Dispatcher.BeginInvoke(DispatcherPriority.Background, resetAction);
7474
}
@@ -96,14 +96,19 @@ public double EllipseOffset
9696

9797
private void SizeChangedHandler(object sender, SizeChangedEventArgs e)
9898
{
99-
var actualWidth = ActualWidth;
99+
var size = this.ActualSize();
100100
var bar = this;
101101
if (this.Visibility == Visibility.Visible && this.IsIndeterminate)
102102
{
103-
bar.ResetStoryboard(actualWidth, true);
103+
bar.ResetStoryboard(size, true);
104104
}
105105
}
106106

107+
private double ActualSize()
108+
{
109+
return this.Orientation == Orientation.Horizontal ? this.ActualWidth : this.ActualHeight;
110+
}
111+
107112
private void ResetStoryboard(double width, bool removeOldStoryboard)
108113
{
109114
if (!this.IsIndeterminate)
@@ -298,11 +303,11 @@ protected override void OnInitialized(EventArgs e)
298303
// only if they haven't been user-set.
299304
if (EllipseDiameter.Equals(0))
300305
{
301-
SetEllipseDiameter(ActualWidth);
306+
SetEllipseDiameter(this.ActualSize());
302307
}
303308
if (EllipseOffset.Equals(0))
304309
{
305-
SetEllipseOffset(ActualWidth);
310+
SetEllipseOffset(this.ActualSize());
306311
}
307312
}
308313
}

MahApps.Metro/Themes/MetroProgressBar.xaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,19 @@
271271
<Trigger Property="IsIndeterminate" Value="False">
272272
<Setter TargetName="DeterminateRoot" Property="Opacity" Value="1" />
273273
</Trigger>
274+
<Trigger Property="Orientation" Value="Vertical">
275+
<Setter TargetName="ContainingGrid" Property="LayoutTransform">
276+
<Setter.Value>
277+
<RotateTransform Angle="270" />
278+
</Setter.Value>
279+
</Setter>
280+
<Setter Property="VerticalAlignment" Value="Stretch" />
281+
<Setter Property="HorizontalAlignment" Value="Center" />
282+
<Setter Property="MinHeight" Value="0" />
283+
<Setter Property="MinWidth" Value="{StaticResource ProgressBarMinHeight}" />
284+
<Setter TargetName="ContainingGrid" Property="Width" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height}"/>
285+
<Setter TargetName="ContainingGrid" Property="Height" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Width}"/>
286+
</Trigger>
274287
</ControlTemplate.Triggers>
275288
</ControlTemplate>
276289
</Setter.Value>

docs/release-notes/1.3.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,4 @@ MahApps.Metro v1.3.0 bug fix and feature release.
163163
- #2473 Cannot use DialogCoordinator from background threads.
164164
- #2551 Feature Request: NonActiveWindowTitleColorBrush
165165
- #2542 NumericUpDown SelectAllOnFocus doesn't work
166+
- #2148 MetroProgressBar orientation does not work (@petvetbr) #2379

0 commit comments

Comments
 (0)