1
- using System . Globalization ;
1
+ using System . Globalization ;
2
2
using System . Windows . Data ;
3
3
using System . Windows . Media ;
4
4
@@ -25,89 +25,77 @@ internal class FloatingHintTextBlockMarginConverter : IMultiValueConverter
25
25
HorizontalAlignment alignment = restingAlignment ;
26
26
if ( scale != 0 )
27
27
{
28
- switch ( floatingAlignment )
28
+ alignment = floatingAlignment switch
29
29
{
30
- case FloatingHintHorizontalAlignment . Inherit :
31
- alignment = restingAlignment ;
32
- break ;
33
- case FloatingHintHorizontalAlignment . Left :
34
- alignment = HorizontalAlignment . Left ;
35
- break ;
36
- case FloatingHintHorizontalAlignment . Center :
37
- alignment = HorizontalAlignment . Center ;
38
- break ;
39
- case FloatingHintHorizontalAlignment . Right :
40
- alignment = HorizontalAlignment . Right ;
41
- break ;
42
- case FloatingHintHorizontalAlignment . Stretch :
43
- alignment = HorizontalAlignment . Stretch ;
44
- break ;
45
- default :
46
- throw new ArgumentOutOfRangeException ( ) ;
47
- }
30
+ FloatingHintHorizontalAlignment . Inherit => restingAlignment ,
31
+ FloatingHintHorizontalAlignment . Left => HorizontalAlignment . Left ,
32
+ FloatingHintHorizontalAlignment . Center => HorizontalAlignment . Center ,
33
+ FloatingHintHorizontalAlignment . Right => HorizontalAlignment . Right ,
34
+ FloatingHintHorizontalAlignment . Stretch => HorizontalAlignment . Stretch ,
35
+ _ => throw new ArgumentOutOfRangeException ( ) ,
36
+ } ;
48
37
}
49
- switch ( alignment )
38
+ double leftThickness = alignment switch
50
39
{
51
- case HorizontalAlignment . Right :
52
- return FloatRight ( ) ;
53
- case HorizontalAlignment . Center :
54
- return FloatCenter ( ) ;
55
- default :
56
- return FloatLeft ( ) ;
57
- }
40
+ HorizontalAlignment . Right => FloatRight ( ) ,
41
+ HorizontalAlignment . Center => FloatCenter ( ) ,
42
+ _ => FloatLeft ( ) ,
43
+ } ;
44
+
45
+ return new Thickness ( Math . Round ( leftThickness ) , 0 , 0 , 0 ) ;
58
46
59
- Thickness FloatLeft ( )
47
+ double FloatLeft ( )
60
48
{
61
49
if ( restingAlignment == HorizontalAlignment . Center )
62
50
{
63
51
// Animate from center to left
64
52
double offset = Math . Max ( 0 , ( availableWidth - desiredWidth ) / 2 ) ;
65
- return new Thickness ( offset - offset * scale , 0 , 0 , 0 ) ;
53
+ return offset - offset * scale ;
66
54
}
67
55
if ( restingAlignment == HorizontalAlignment . Right )
68
56
{
69
57
// Animate from right to left
70
58
double offset = Math . Max ( 0 , availableWidth - desiredWidth ) ;
71
- return new Thickness ( offset - offset * scale , 0 , 0 , 0 ) ;
59
+ return offset - offset * scale ;
72
60
}
73
- return new Thickness ( 0 ) ;
61
+ return 0 ;
74
62
}
75
63
76
- Thickness FloatCenter ( )
64
+ double FloatCenter ( )
77
65
{
78
66
if ( restingAlignment == HorizontalAlignment . Left || restingAlignment == HorizontalAlignment . Stretch )
79
67
{
80
68
// Animate from left to center
81
69
double offset = Math . Max ( 0 , ( availableWidth - desiredWidth * scaleMultiplier ) / 2 ) ;
82
- return new Thickness ( offset * scale , 0 , 0 , 0 ) ;
70
+ return offset * scale ;
83
71
}
84
72
if ( restingAlignment == HorizontalAlignment . Right )
85
73
{
86
74
// Animate from right to center
87
75
double startOffset = Math . Max ( 0 , availableWidth - desiredWidth ) ;
88
76
double endOffset = Math . Max ( 0 , ( availableWidth - desiredWidth ) / 2 ) ;
89
77
double endOffsetDelta = startOffset - endOffset ;
90
- return new Thickness ( endOffset + endOffsetDelta * ( 1 - scale ) , 0 , 0 , 0 ) ;
78
+ return endOffset + endOffsetDelta * ( 1 - scale ) ;
91
79
}
92
- return new Thickness ( Math . Max ( 0 , availableWidth - desiredWidth * scaleMultiplier ) / 2 , 0 , 0 , 0 ) ;
80
+ return Math . Max ( 0 , availableWidth - desiredWidth * scaleMultiplier ) / 2 ;
93
81
}
94
82
95
- Thickness FloatRight ( )
83
+ double FloatRight ( )
96
84
{
97
85
if ( restingAlignment == HorizontalAlignment . Left || restingAlignment == HorizontalAlignment . Stretch )
98
86
{
99
87
// Animate from left to right
100
88
double offset = Math . Max ( 0 , availableWidth - desiredWidth * scaleMultiplier ) ;
101
- return new Thickness ( offset * scale , 0 , 0 , 0 ) ;
89
+ return offset * scale ;
102
90
}
103
91
if ( restingAlignment == HorizontalAlignment . Center )
104
92
{
105
93
// Animate from center to right
106
94
double startOffset = Math . Max ( 0 , ( availableWidth - desiredWidth ) / 2 ) ;
107
95
double endOffsetDelta = Math . Max ( 0 , availableWidth - desiredWidth * scaleMultiplier ) - startOffset ;
108
- return new Thickness ( startOffset + endOffsetDelta * scale , 0 , 0 , 0 ) ;
96
+ return startOffset + endOffsetDelta * scale ;
109
97
}
110
- return new Thickness ( Math . Max ( 0 , availableWidth - desiredWidth * scaleMultiplier ) , 0 , 0 , 0 ) ;
98
+ return Math . Max ( 0 , availableWidth - desiredWidth * scaleMultiplier ) ;
111
99
}
112
100
}
113
101
0 commit comments