summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorPaul DiPietro <pauldipietro@users.noreply.github.com>2016-12-05 03:43:24 -0700
committerRui Marinho <me@ruimarinho.net>2016-12-05 10:43:24 +0000
commit3692786c3a0f9ba01ffe9516caa624a018ac885a (patch)
tree788d13326eb8cd5d9a41330e68ecf1cec6bd39c3 /Xamarin.Forms.Platform.WinRT
parent17280b260f07b12a23bb4af2679183b39beb8fd6 (diff)
downloadxamarin-forms-3692786c3a0f9ba01ffe9516caa624a018ac885a.tar.gz
xamarin-forms-3692786c3a0f9ba01ffe9516caa624a018ac885a.tar.bz2
xamarin-forms-3692786c3a0f9ba01ffe9516caa624a018ac885a.zip
[WinRT/UWP] Adjust margin for centered Slider (#604)
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/SliderRenderer.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs b/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs
index ee7a8adc..cf188f15 100644
--- a/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
+using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls.Primitives;
#if WINDOWS_UWP
@@ -24,6 +25,25 @@ namespace Xamarin.Forms.Platform.WinRT
SetNativeControl(slider);
slider.ValueChanged += OnNativeValueCHanged;
+
+ // Even when using Center/CenterAndExpand, a Slider has an oddity where it looks
+ // off-center in its layout by a smidge. The default templates are slightly different
+ // between 8.1/UWP; the 8.1 rows are 17/Auto/32 and UWP are 18/Auto/18. The value of
+ // the hardcoded 8.1 rows adds up to 49 (when halved is 24.5) and UWP are 36 (18). Using
+ // a difference of about 6 pixels to correct this oddity seems to make them both center
+ // more correctly.
+ //
+ // The VerticalAlignment needs to be set as well since a control would not actually be
+ // centered if a larger HeightRequest is set.
+ if (Element.VerticalOptions.Alignment == LayoutAlignment.Center && Control.Orientation == Windows.UI.Xaml.Controls.Orientation.Horizontal)
+ {
+ Control.VerticalAlignment = VerticalAlignment.Center;
+#if WINDOWS_UWP
+ slider.Margin = new Windows.UI.Xaml.Thickness(0, 7, 0, 0);
+#else
+ slider.Margin = new Windows.UI.Xaml.Thickness(0, 13, 0, 0);
+#endif
+ }
}
double stepping = Math.Min((e.NewElement.Maximum - e.NewElement.Minimum) / 10, 1);