-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathTextBoxHorizontalScrollBarMarginConverter.cs
More file actions
43 lines (39 loc) · 1.75 KB
/
TextBoxHorizontalScrollBarMarginConverter.cs
File metadata and controls
43 lines (39 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Globalization;
using System.Windows.Data;
namespace MaterialDesignThemes.Wpf.Converters.Internal;
public class TextBoxHorizontalScrollBarMarginConverter : IMultiValueConverter
{
public object? Convert(object?[]? values, Type targetType, object? parameter, CultureInfo culture)
{
if (values is [
double leadingIconWidth,
Thickness leadingIconMargin,
double prefixTextWidth,
Thickness prefixTextMargin,
bool isMouseOver,
bool hasKeyboardFocus,
bool hasOutlinedTextField,
Thickness normalBorder,
Thickness activeBorder])
{
double iconMargin = leadingIconWidth > 0 ? leadingIconMargin.Left + leadingIconMargin.Right : 0;
double prefixMargin = prefixTextWidth > 0 ? prefixTextMargin.Left + prefixTextMargin.Right : 0;
double offset = leadingIconWidth + iconMargin + prefixTextWidth + prefixMargin;
double bottomOffset = 0;
double topOffset = 0;
if (hasOutlinedTextField && (isMouseOver || hasKeyboardFocus))
{
double horizDelta = activeBorder.Left - normalBorder.Left;
double vertDeltaTop = activeBorder.Top - normalBorder.Top;
double vertDeltaBottom = activeBorder.Bottom - normalBorder.Bottom;
offset -= horizDelta;
topOffset += vertDeltaTop;
bottomOffset -= vertDeltaBottom;
}
return new Thickness(offset, topOffset, 0, bottomOffset);
}
return new Thickness(0);
}
public object?[]? ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture)
=> throw new NotImplementedException();
}