Skip to content

Commit 428f141

Browse files
MaterialDesignOutlinedTextBox floating hint position bug fix + Refactor FloatingHintOffsetCalculationConverter (#2218)
* Floating Hint fix for outlined TextBox style * Made Converter class more readable Co-authored-by: Michel Michels <[email protected]>
1 parent e6c1f28 commit 428f141

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

MaterialDesignThemes.Wpf/Converters/FloatingHintOffsetCalculationConverter.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,35 @@ internal class FloatingHintOffsetCalculationConverter : IMultiValueConverter
1010
{
1111
public object Convert(object[] values, Type targetType, object? parameter, CultureInfo culture)
1212
{
13-
var hintHeight = ((FontFamily)values[0]).LineSpacing
14-
* (double)values[1]; // fontSize
15-
var floatingHintHeight = hintHeight
16-
* (double)values[2]; // floatingScale
13+
var fontFamily = (FontFamily)values[0];
14+
double fontSize = (double)values[1];
15+
double floatingScale = (double)values[2];
1716

18-
var offset = (values.Length > 3 ? values[3] : null) switch
17+
double hintHeight = fontFamily.LineSpacing * fontSize;
18+
double floatingHintHeight = hintHeight * floatingScale;
19+
20+
double offset = (values.Length > 3 ? values[3] : null) switch
1921
{
2022
Thickness padding => floatingHintHeight / 2 + padding.Top,
2123
double parentHeight => (parentHeight - hintHeight + floatingHintHeight) / 2,
2224
_ => floatingHintHeight
2325
};
2426

25-
if (targetType == typeof(Point)) // offset
27+
if (IsType<Point>(targetType))
28+
{
2629
return new Point(0, -offset);
27-
if (targetType == typeof(Thickness)) // margin
30+
}
31+
32+
if (IsType<Thickness>(targetType))
33+
{
2834
return new Thickness(0, offset, 0, 0);
35+
}
36+
2937
throw new NotSupportedException(targetType.FullName);
3038
}
3139

3240
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotSupportedException();
41+
42+
private bool IsType<T>(Type type) => type == typeof(T);
3343
}
3444
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="FontFamily" />
246246
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="FontSize" />
247247
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(wpf:HintAssist.FloatingScale)" />
248-
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ActualHeight" />
248+
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Padding" />
249249
</MultiBinding>
250250
</Setter.Value>
251251
</Setter>

0 commit comments

Comments
 (0)