--- /dev/null
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Github, 6556, "Button.CornerRadius doesn't work on WPF", PlatformAffected.WPF)]
+ public class Issue6556 : TestContentPage
+ {
+ protected override void Init()
+ {
+ var sl = new StackLayout { Padding = new Size(20, 20) };
+ sl.Children.Add(new TestButton(0));
+ sl.Children.Add(new TestButton(5));
+ sl.Children.Add(new TestButton(10));
+ sl.Children.Add(new TestButton(20));
+ sl.Children.Add(new Button()
+ {
+ Text = "Round",
+ WidthRequest = 50,
+ HeightRequest = 50,
+ CornerRadius = 25,
+ BorderWidth = 5,
+ HorizontalOptions = LayoutOptions.Center
+ });
+ Content = sl;
+ }
+
+ class TestButton : Button
+ {
+ public TestButton(int cr)
+ {
+ Text = $"radius is {cr}";
+ BorderWidth = 5;
+ CornerRadius = cr;
+ }
+ }
+ }
+}
\ No newline at end of file
<Compile Include="$(MSBuildThisFileDirectory)Issue4606.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8186.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3475.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Issue6556.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue5830.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue6476.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7396.cs" />
--- /dev/null
+using System.Linq;
+using System.Windows;
+using System.Windows.Controls;
+using WButton = System.Windows.Controls.Button;
+
+namespace Xamarin.Forms.Platform.WPF.Controls
+{
+ public class FormsButton : WButton
+ {
+ public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register(nameof(CornerRadius), typeof(int), typeof(FormsButton),
+ new PropertyMetadata(default(int), OnCornerRadiusChanged));
+
+ Border _contentPresenter;
+
+
+ public int CornerRadius
+ {
+ get
+ {
+ return (int)GetValue(CornerRadiusProperty);
+ }
+ set
+ {
+ SetValue(CornerRadiusProperty, value);
+ }
+ }
+
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+
+ _contentPresenter = this.GetChildren<Border>().FirstOrDefault();
+ UpdateCornerRadius();
+ }
+
+ static void OnCornerRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ ((FormsButton)d).UpdateCornerRadius();
+ }
+
+ void UpdateCornerRadius()
+ {
+ if (_contentPresenter != null)
+ _contentPresenter.CornerRadius = new System.Windows.CornerRadius(CornerRadius);
+ }
+ }
+}
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Xamarin.Forms.Internals;
+using Xamarin.Forms.Platform.WPF.Controls;
using WButton = System.Windows.Controls.Button;
using WImage = System.Windows.Controls.Image;
using WThickness = System.Windows.Thickness;
namespace Xamarin.Forms.Platform.WPF
{
- public class ButtonRenderer : ViewRenderer<Button, WButton>
+ public class ButtonRenderer : ViewRenderer<Button, FormsButton>
{
bool _fontApplied;
{
if (Control == null) // construct and SetNativeControl and suscribe control event
{
- SetNativeControl(new WButton());
+ SetNativeControl(new FormsButton());
Control.Click += HandleButtonClick;
}
if (Element.BorderColor != Color.Default)
UpdateBorderColor();
- if (Element.BorderWidth != 0)
+ if (Element.IsSet(Button.BorderWidthProperty) && Element.BorderWidth != (double)Button.BorderWidthProperty.DefaultValue)
UpdateBorderWidth();
+ if (Element.IsSet(Button.CornerRadiusProperty) && Element.CornerRadius != (int)Button.CornerRadiusProperty.DefaultValue)
+ UpdateCornerRadius();
+
if (Element.IsSet(Button.PaddingProperty))
UpdatePadding();
UpdateBorderWidth();
UpdatePadding();
}
+ else if (e.PropertyName == Button.CornerRadiusProperty.PropertyName)
+ UpdateCornerRadius();
else if (e.PropertyName == Button.PaddingProperty.PropertyName)
UpdatePadding();
}
{
Control.BorderThickness = Element.BorderWidth <= 0d ? new WThickness(1) : new WThickness(Element.BorderWidth);
}
+ void UpdateCornerRadius()
+ {
+ Control.CornerRadius = Element.CornerRadius;
+ }
async void UpdateContent()
{
<Compile Include="Controls\FormsAppBar.cs" />
<Compile Include="Controls\FormsAppBarButton.cs" />
<Compile Include="Controls\FormsBitmapIcon.cs" />
+ <Compile Include="Controls\FormsButton.cs" />
<Compile Include="Controls\FormsCarouselPage.cs" />
<Compile Include="Controls\FormsContentControl.cs" />
<Compile Include="Controls\FormsContentDialog.cs" />