2016-03-22 23:02:25 +03:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
2016-03-30 01:41:39 +03:00
|
|
|
|
using Windows.UI.Xaml.Media;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
#if WINDOWS_UWP
|
2016-03-30 01:41:39 +03:00
|
|
|
|
using WContentPresenter = Windows.UI.Xaml.Controls.ContentPresenter;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
namespace Xamarin.Forms.Platform.UWP
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
namespace Xamarin.Forms.Platform.WinRT
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
public class FormsButton : Windows.UI.Xaml.Controls.Button
|
|
|
|
|
{
|
2016-03-30 01:41:39 +03:00
|
|
|
|
public static readonly DependencyProperty BorderRadiusProperty = DependencyProperty.Register(nameof(BorderRadius), typeof(int), typeof(FormsButton),
|
2016-03-22 23:02:25 +03:00
|
|
|
|
new PropertyMetadata(default(int), OnBorderRadiusChanged));
|
|
|
|
|
|
2016-03-30 01:41:39 +03:00
|
|
|
|
public static readonly DependencyProperty BackgroundColorProperty = DependencyProperty.Register(nameof(BackgroundColor), typeof(Brush), typeof(FormsButton),
|
|
|
|
|
new PropertyMetadata(default(Brush), OnBackgroundColorChanged));
|
|
|
|
|
|
|
|
|
|
#if WINDOWS_UWP
|
|
|
|
|
WContentPresenter _contentPresenter;
|
|
|
|
|
#else
|
2016-03-22 23:02:25 +03:00
|
|
|
|
Border _border;
|
2016-03-30 01:41:39 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
public Brush BackgroundColor
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (Brush)GetValue(BackgroundColorProperty);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetValue(BackgroundColorProperty, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
public int BorderRadius
|
|
|
|
|
{
|
2016-03-30 01:41:39 +03:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (int)GetValue(BorderRadiusProperty);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetValue(BorderRadiusProperty, value);
|
|
|
|
|
}
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnApplyTemplate()
|
|
|
|
|
{
|
|
|
|
|
base.OnApplyTemplate();
|
|
|
|
|
|
2016-03-30 01:41:39 +03:00
|
|
|
|
#if WINDOWS_UWP
|
|
|
|
|
_contentPresenter = GetTemplateChild("ContentPresenter") as WContentPresenter;
|
|
|
|
|
#else
|
2016-03-22 23:02:25 +03:00
|
|
|
|
_border = GetTemplateChild("Border") as Border;
|
2016-03-30 01:41:39 +03:00
|
|
|
|
#endif
|
|
|
|
|
UpdateBackgroundColor();
|
2016-03-22 23:02:25 +03:00
|
|
|
|
UpdateBorderRadius();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 01:41:39 +03:00
|
|
|
|
static void OnBackgroundColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
((FormsButton)d).UpdateBackgroundColor();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
|
static void OnBorderRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
((FormsButton)d).UpdateBorderRadius();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 01:41:39 +03:00
|
|
|
|
void UpdateBackgroundColor()
|
|
|
|
|
{
|
2016-11-08 18:38:17 +03:00
|
|
|
|
if (BackgroundColor == null)
|
|
|
|
|
BackgroundColor = Background;
|
|
|
|
|
|
2016-03-30 01:41:39 +03:00
|
|
|
|
#if WINDOWS_UWP
|
|
|
|
|
if (_contentPresenter != null)
|
|
|
|
|
_contentPresenter.Background = BackgroundColor;
|
|
|
|
|
#else
|
|
|
|
|
if (_border != null)
|
|
|
|
|
_border.Background = BackgroundColor;
|
|
|
|
|
#endif
|
2016-11-08 18:38:17 +03:00
|
|
|
|
Background = Color.Transparent.ToBrush();
|
2016-03-30 01:41:39 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
|
void UpdateBorderRadius()
|
|
|
|
|
{
|
|
|
|
|
|
2016-03-30 01:41:39 +03:00
|
|
|
|
#if WINDOWS_UWP
|
|
|
|
|
if (_contentPresenter != null)
|
|
|
|
|
_contentPresenter.CornerRadius = new CornerRadius(BorderRadius);
|
|
|
|
|
#else
|
|
|
|
|
if (_border != null)
|
|
|
|
|
_border.CornerRadius = new CornerRadius(BorderRadius);
|
|
|
|
|
#endif
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|