This commit is contained in:
NaBian committed 2019-06-21 00:42:02 +08:00
1 parent 34cc6b9b8b
commit 78c49e7aaf
33 files changed
+412 -28

No files matched your search

@@ -0,0 +1,36 @@
//referenced from https://stackoverflow.com/a/5650367/9639378
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
namespace HandyControl.Tools.Converter
{
public class BorderCircularClipConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length == 3 && values[0] is double width && values[1] is double height && values[2] is CornerRadius radius)
{
if (width < double.Epsilon || height < double.Epsilon)
{
return Geometry.Empty;
}
var clip = new RectangleGeometry(new Rect(0, 0, width, height), radius.TopLeft, radius.TopLeft);
clip.Freeze();
return clip;
}
return DependencyProperty.UnsetValue;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}
@@ -1,6 +1,4 @@
//referenced from https://stackoverflow.com/a/5650367/9639378
using System;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
@@ -19,7 +17,23 @@ namespace HandyControl.Tools.Converter
return Geometry.Empty;
}
var clip = new RectangleGeometry(new Rect(0, 0, width, height), radius.TopLeft, radius.TopLeft);
var clip = new PathGeometry
{
Figures = new PathFigureCollection
{
new PathFigure(new Point(radius.TopLeft, 0), new PathSegment[]
{
new LineSegment(new Point(width - radius.TopRight, 0), false),
new ArcSegment(new Point(width, radius.TopRight), new Size(radius.TopRight, radius.TopRight), 90, false, SweepDirection.Clockwise, false),
new LineSegment(new Point(width, height - radius.BottomRight), false),
new ArcSegment(new Point(width - radius.BottomRight, height), new Size(radius.BottomRight, radius.BottomRight), 90, false, SweepDirection.Clockwise, false),
new LineSegment(new Point(radius.BottomLeft, height), false),
new ArcSegment(new Point(0, height - radius.BottomLeft), new Size(radius.BottomLeft, radius.BottomLeft), 90, false, SweepDirection.Clockwise, false),
new LineSegment(new Point(0, radius.TopLeft), false),
new ArcSegment(new Point(radius.TopLeft, 0), new Size(radius.TopLeft, radius.TopLeft), 90, false, SweepDirection.Clockwise, false),
}, false)
}
};
clip.Freeze();
return clip;