summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorRui Marinho <me@ruimarinho.net>2016-04-01 11:07:17 +0100
committerRui Marinho <me@ruimarinho.net>2016-04-01 11:07:17 +0100
commit39787d31aa4c5d2d3d13b9656cb929e03fc88e04 (patch)
tree33f2353bff787632181257f18de0634e02ed581a /Xamarin.Forms.Platform.WinRT
parentd22a5c7c32701aa6b830b09e52d8e272a9d0a97f (diff)
parent0817c7a4580a01fe03336276e3ec325b9c1bdf2f (diff)
downloadxamarin-forms-39787d31aa4c5d2d3d13b9656cb929e03fc88e04.tar.gz
xamarin-forms-39787d31aa4c5d2d3d13b9656cb929e03fc88e04.tar.bz2
xamarin-forms-39787d31aa4c5d2d3d13b9656cb929e03fc88e04.zip
Merge pull request #31 from xamarin/fix-bugzilla39464
[W] Button BG Color & BorderRadius are consistent
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs10
-rw-r--r--Xamarin.Forms.Platform.WinRT/FormsButton.cs65
2 files changed, 68 insertions, 7 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
index bcba31cc..04c39caf 100644
--- a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
@@ -88,6 +88,14 @@ namespace Xamarin.Forms.Platform.WinRT
}
}
+ protected override void UpdateBackgroundColor()
+ {
+ // Button is a special case; we don't want to set the Control's background
+ // because it goes outside the bounds of the Border/ContentPresenter,
+ // which is where we might change the BorderRadius to create a rounded shape.
+ return;
+ }
+
void OnButtonClick(object sender, RoutedEventArgs e)
{
Button buttonView = Element;
@@ -97,7 +105,7 @@ namespace Xamarin.Forms.Platform.WinRT
void UpdateBackground()
{
- Control.Background = Element.BackgroundColor != Color.Default ? Element.BackgroundColor.ToBrush() : (Brush)Windows.UI.Xaml.Application.Current.Resources["ButtonBackgroundThemeBrush"];
+ Control.BackgroundColor = Element.BackgroundColor != Color.Default ? Element.BackgroundColor.ToBrush() : (Brush)Windows.UI.Xaml.Application.Current.Resources["ButtonBackgroundThemeBrush"];
}
void UpdateBorderColor()
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