From b204632ea9cdaec7923999bc17b8832da0754f4a Mon Sep 17 00:00:00 2001 From: punker76 Date: Sun, 28 Feb 2021 12:43:03 +0100 Subject: [PATCH 1/2] (GH-4050) Add CornerRadiusFilterConverter Filters a CornerRadius by the given Filter property. Result can be a new CornerRadius or a value of it's 4 corners. --- .../Converters/CornerRadiusFilterConverter.cs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/MahApps.Metro/Converters/CornerRadiusFilterConverter.cs diff --git a/src/MahApps.Metro/Converters/CornerRadiusFilterConverter.cs b/src/MahApps.Metro/Converters/CornerRadiusFilterConverter.cs new file mode 100644 index 0000000000..14c1da0935 --- /dev/null +++ b/src/MahApps.Metro/Converters/CornerRadiusFilterConverter.cs @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace MahApps.Metro.Converters +{ + /// + /// Filters a CornerRadius by the given Filter property. Result can be a new CornerRadius or a value of it's 4 corners. + /// + public class CornerRadiusFilterConverter : IValueConverter + { + public RadiusType Filter { get; set; } = RadiusType.None; + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is CornerRadius cornerRadius) + { + var filter = this.Filter; + + // yes, we can override it with the parameter value + if (parameter is RadiusType radiusType) + { + filter = radiusType; + } + + switch (filter) + { + default: + return cornerRadius; + case RadiusType.Left: + return new CornerRadius(cornerRadius.TopLeft, 0, 0, cornerRadius.BottomLeft); + case RadiusType.Top: + return new CornerRadius(cornerRadius.TopLeft, cornerRadius.TopRight, 0, 0); + case RadiusType.Right: + return new CornerRadius(0, cornerRadius.TopRight, cornerRadius.BottomRight, 0); + case RadiusType.Bottom: + return new CornerRadius(0, 0, cornerRadius.BottomRight, cornerRadius.BottomLeft); + case RadiusType.TopLeft: + return cornerRadius.TopLeft; + case RadiusType.TopRight: + return cornerRadius.TopRight; + case RadiusType.BottomRight: + return cornerRadius.BottomRight; + case RadiusType.BottomLeft: + return cornerRadius.BottomLeft; + } + } + + return Binding.DoNothing; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + // for now no back converting + return DependencyProperty.UnsetValue; + } + } +} \ No newline at end of file From 0c7ac72f578c2adf69c8cc53c9729da6dd0cf0b9 Mon Sep 17 00:00:00 2001 From: punker76 Date: Sun, 28 Feb 2021 12:47:01 +0100 Subject: [PATCH 2/2] (GH-4050) Add new CheckCornerRadius to CheckBoxHelper The CheckCornerRadius property allows users to control the roundness of the CheckBox corners independently by setting a radius value for each corner. --- .../ExampleViews/ButtonsExample.xaml | 2 +- .../Controls/Helper/CheckBoxHelper.cs | 30 +++++++++++++++++++ .../Styles/Controls.CheckBox.xaml | 7 ++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/ButtonsExample.xaml b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/ButtonsExample.xaml index f458486a20..1a42f74022 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/ButtonsExample.xaml +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/ButtonsExample.xaml @@ -321,7 +321,7 @@