summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/FormsButton.cs
blob: 73c2f9229e04f323754e8148d829a9a9e6605023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

#if WINDOWS_UWP

namespace Xamarin.Forms.Platform.UWP
#else

namespace Xamarin.Forms.Platform.WinRT
#endif
{
	public class FormsButton : Windows.UI.Xaml.Controls.Button
	{
		public static readonly DependencyProperty BorderRadiusProperty = DependencyProperty.Register("BorderRadius", typeof(int), typeof(FormsButton),
			new PropertyMetadata(default(int), OnBorderRadiusChanged));

		Border _border;

		public int BorderRadius
		{
			get { return (int)GetValue(BorderRadiusProperty); }
			set { SetValue(BorderRadiusProperty, value); }
		}

		protected override void OnApplyTemplate()
		{
			base.OnApplyTemplate();

			_border = GetTemplateChild("Border") as Border;
			UpdateBorderRadius();
		}

		static void OnBorderRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			((FormsButton)d).UpdateBorderRadius();
		}

		void UpdateBorderRadius()
		{
			if (_border == null)
				return;

			_border.CornerRadius = new CornerRadius(BorderRadius);
		}
	}
}