diff options
author | Samantha Houts <samantha.houts@xamarin.com> | 2016-03-29 15:41:39 -0700 |
---|---|---|
committer | Samantha Houts <samantha.houts@xamarin.com> | 2016-03-29 15:41:39 -0700 |
commit | 0817c7a4580a01fe03336276e3ec325b9c1bdf2f (patch) | |
tree | b0ca94775dc87da9f48ef700f195119628feaece /Xamarin.Forms.Platform.WinRT/FormsButton.cs | |
parent | 346338b5dc3c84b80969376bc87e886f4ef880a8 (diff) | |
download | xamarin-forms-0817c7a4580a01fe03336276e3ec325b9c1bdf2f.tar.gz xamarin-forms-0817c7a4580a01fe03336276e3ec325b9c1bdf2f.tar.bz2 xamarin-forms-0817c7a4580a01fe03336276e3ec325b9c1bdf2f.zip |
[W] Button BG Color & BorderRadius are consistent
UWP Buttons now respect the BorderRadius.
BackgroundColor no longer extends past the Border.
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/FormsButton.cs')
-rw-r--r-- | Xamarin.Forms.Platform.WinRT/FormsButton.cs | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/FormsButton.cs b/Xamarin.Forms.Platform.WinRT/FormsButton.cs index 73c2f922..ffe75d4f 100644 --- a/Xamarin.Forms.Platform.WinRT/FormsButton.cs +++ b/Xamarin.Forms.Platform.WinRT/FormsButton.cs @@ -1,7 +1,9 @@ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; #if WINDOWS_UWP +using WContentPresenter = Windows.UI.Xaml.Controls.ContentPresenter; namespace Xamarin.Forms.Platform.UWP #else @@ -11,36 +13,87 @@ namespace Xamarin.Forms.Platform.WinRT { public class FormsButton : Windows.UI.Xaml.Controls.Button { - public static readonly DependencyProperty BorderRadiusProperty = DependencyProperty.Register("BorderRadius", typeof(int), typeof(FormsButton), + public static readonly DependencyProperty BorderRadiusProperty = DependencyProperty.Register(nameof(BorderRadius), typeof(int), typeof(FormsButton), new PropertyMetadata(default(int), OnBorderRadiusChanged)); + public static readonly DependencyProperty BackgroundColorProperty = DependencyProperty.Register(nameof(BackgroundColor), typeof(Brush), typeof(FormsButton), + new PropertyMetadata(default(Brush), OnBackgroundColorChanged)); + +#if WINDOWS_UWP + WContentPresenter _contentPresenter; +#else Border _border; +#endif + + public Brush BackgroundColor + { + get + { + return (Brush)GetValue(BackgroundColorProperty); + } + set + { + SetValue(BackgroundColorProperty, value); + } + } public int BorderRadius { - get { return (int)GetValue(BorderRadiusProperty); } - set { SetValue(BorderRadiusProperty, value); } + get + { + return (int)GetValue(BorderRadiusProperty); + } + set + { + SetValue(BorderRadiusProperty, value); + } } protected override void OnApplyTemplate() { base.OnApplyTemplate(); +#if WINDOWS_UWP + _contentPresenter = GetTemplateChild("ContentPresenter") as WContentPresenter; +#else _border = GetTemplateChild("Border") as Border; +#endif + UpdateBackgroundColor(); UpdateBorderRadius(); } + static void OnBackgroundColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((FormsButton)d).UpdateBackgroundColor(); + } + static void OnBorderRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ((FormsButton)d).UpdateBorderRadius(); } + void UpdateBackgroundColor() + { + Background = Color.Transparent.ToBrush(); +#if WINDOWS_UWP + if (_contentPresenter != null) + _contentPresenter.Background = BackgroundColor; +#else + if (_border != null) + _border.Background = BackgroundColor; +#endif + } + void UpdateBorderRadius() { - if (_border == null) - return; - _border.CornerRadius = new CornerRadius(BorderRadius); +#if WINDOWS_UWP + if (_contentPresenter != null) + _contentPresenter.CornerRadius = new CornerRadius(BorderRadius); +#else + if (_border != null) + _border.CornerRadius = new CornerRadius(BorderRadius); +#endif } } }
\ No newline at end of file |