Skip to content

Commit 5175f72

Browse files
committed
CornerRadius Extract converter
1 parent 4348412 commit 5175f72

File tree

3 files changed

+86
-7
lines changed

3 files changed

+86
-7
lines changed

iNKORE.UI.WPF.sln

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{D6C9
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfApp1", "source\samples\WpfApp1\WpfApp1.csproj", "{B58816CF-AC94-4096-89A0-4EE78167DECB}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "iNKORE.UI.WPF.DirectX", "source\iNKORE.UI.WPF.DirectX\iNKORE.UI.WPF.DirectX.csproj", "{73154957-3D91-48DA-8068-D425B523ED93}"
13-
EndProject
1412
Global
1513
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1614
Debug|Any CPU = Debug|Any CPU
@@ -25,10 +23,6 @@ Global
2523
{B58816CF-AC94-4096-89A0-4EE78167DECB}.Debug|Any CPU.Build.0 = Debug|Any CPU
2624
{B58816CF-AC94-4096-89A0-4EE78167DECB}.Release|Any CPU.ActiveCfg = Release|Any CPU
2725
{B58816CF-AC94-4096-89A0-4EE78167DECB}.Release|Any CPU.Build.0 = Release|Any CPU
28-
{73154957-3D91-48DA-8068-D425B523ED93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29-
{73154957-3D91-48DA-8068-D425B523ED93}.Debug|Any CPU.Build.0 = Debug|Any CPU
30-
{73154957-3D91-48DA-8068-D425B523ED93}.Release|Any CPU.ActiveCfg = Release|Any CPU
31-
{73154957-3D91-48DA-8068-D425B523ED93}.Release|Any CPU.Build.0 = Release|Any CPU
3226
EndGlobalSection
3327
GlobalSection(SolutionProperties) = preSolution
3428
HideSolutionNode = FALSE
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Data;
8+
9+
namespace iNKORE.UI.WPF.Converters
10+
{
11+
/// <summary>
12+
/// Extracts a single member of a CornerRadius object.
13+
/// For example, if you have a CornerRadius of 5,5,5,5 and you want to extract the TopLeft value, you would use this converter with the TargetMember set to TopLeft.
14+
/// </summary>
15+
public class CornerRadiusExtractionConverter: IValueConverter
16+
{
17+
public CornerRadiusExtractMember TargetMember { get; set; }
18+
19+
public double Scale { get; set; } = 1;
20+
21+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
22+
{
23+
if (value is CornerRadius)
24+
{
25+
var result = 0d;
26+
CornerRadius cornerRadius = (CornerRadius)value;
27+
28+
switch (TargetMember)
29+
{
30+
case CornerRadiusExtractMember.TopLeft:
31+
result = cornerRadius.TopLeft;
32+
break;
33+
case CornerRadiusExtractMember.TopRight:
34+
result = cornerRadius.TopRight;
35+
break;
36+
case CornerRadiusExtractMember.BottomRight:
37+
result = cornerRadius.BottomRight;
38+
break;
39+
case CornerRadiusExtractMember.BottomLeft:
40+
result = cornerRadius.BottomLeft;
41+
break;
42+
default:
43+
result = cornerRadius.TopLeft;
44+
break;
45+
}
46+
47+
return result * Scale;
48+
}
49+
50+
return null;
51+
}
52+
53+
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
54+
{
55+
if (value is double)
56+
{
57+
double doubleValue = (double)value / Scale;
58+
59+
switch (TargetMember)
60+
{
61+
case CornerRadiusExtractMember.TopLeft:
62+
return new CornerRadius(doubleValue, 0, 0, 0);
63+
case CornerRadiusExtractMember.TopRight:
64+
return new CornerRadius(0, doubleValue, 0, 0);
65+
case CornerRadiusExtractMember.BottomRight:
66+
return new CornerRadius(0, 0, doubleValue, 0);
67+
case CornerRadiusExtractMember.BottomLeft:
68+
return new CornerRadius(0, 0, 0, doubleValue);
69+
default:
70+
return new CornerRadius(doubleValue);
71+
}
72+
}
73+
74+
return new CornerRadius(0);
75+
}
76+
}
77+
78+
public enum CornerRadiusExtractMember
79+
{
80+
TopLeft,
81+
TopRight,
82+
BottomRight,
83+
BottomLeft
84+
}
85+
}

source/iNKORE.UI.WPF/Converters/CornerRadiusFilterConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class CornerRadiusFilterConverter : DependencyObject, IValueConverter
1414

1515
public static CornerRadiusEx Convert(CornerRadiusEx radius, CornerRadiusFilterKind filterKind, double scale = 1)
1616
{
17-
CornerRadiusEx result = radius;
17+
CornerRadiusEx result = new CornerRadiusEx(0);
1818

1919
if (filterKind.HasFlag(CornerRadiusFilterKind.TopLeft))
2020
{

0 commit comments

Comments
 (0)