Skip to content

Commit 7992d4c

Browse files
Only consider hover/focus when style is outlined
1 parent b826941 commit 7992d4c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/MaterialDesignThemes.Wpf/Converters/TextBoxHorizontalScrollBarMarginConverter.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,25 @@ public class TextBoxHorizontalScrollBarMarginConverter : IMultiValueConverter
1313
double prefixTextWidth,
1414
Thickness prefixTextMargin,
1515
bool isMouseOver,
16-
bool hasKeyboardFocus])
16+
bool hasKeyboardFocus,
17+
bool isOutlinedStyle,
18+
Thickness normalBorder,
19+
Thickness activeBorder])
1720
{
1821
double iconMargin = leadingIconWidth > 0 ? leadingIconMargin.Left + leadingIconMargin.Right : 0;
1922
double prefixMargin = prefixTextWidth > 0 ? prefixTextMargin.Left + prefixTextMargin.Right : 0;
2023
double offset = leadingIconWidth + iconMargin + prefixTextWidth + prefixMargin;
2124
double bottomOffset = 0;
2225
double topOffset = 0;
2326

24-
if (isMouseOver || hasKeyboardFocus)
27+
if (isOutlinedStyle && (isMouseOver || hasKeyboardFocus))
2528
{
26-
offset -= 1;
27-
topOffset += 1;
28-
bottomOffset -= 1;
29+
double horizDelta = activeBorder.Left - normalBorder.Left;
30+
double vertDeltaTop = activeBorder.Top - normalBorder.Top;
31+
double vertDeltaBottom = activeBorder.Bottom - normalBorder.Bottom;
32+
offset -= horizDelta;
33+
topOffset += vertDeltaTop;
34+
bottomOffset -= vertDeltaBottom;
2935
}
3036
return new Thickness(offset, topOffset, 0, bottomOffset);
3137
}

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,11 @@
314314
<Binding ElementName="LeadingPackIcon" Path="Margin" />
315315
<Binding ElementName="PrefixTextBlock" Path="ActualWidth" />
316316
<Binding ElementName="PrefixTextBlock" Path="Margin" />
317-
<Binding RelativeSource="{RelativeSource AncestorType=TextBox}" Path="IsMouseOver" />
318-
<Binding RelativeSource="{RelativeSource AncestorType=TextBox}" Path="IsKeyboardFocusWithin" />
317+
<Binding Path="IsMouseOver" RelativeSource="{RelativeSource TemplatedParent}" />
318+
<Binding Path="IsKeyboardFocusWithin" RelativeSource="{RelativeSource TemplatedParent}" />
319+
<Binding Path="(wpf:TextFieldAssist.HasOutlinedTextField)" RelativeSource="{RelativeSource TemplatedParent}" />
320+
<Binding Path="BorderThickness" RelativeSource="{RelativeSource TemplatedParent}" />
321+
<Binding Path="(wpf:TextFieldAssist.OutlinedBorderActiveThickness)" RelativeSource="{RelativeSource TemplatedParent}" />
319322
</MultiBinding>
320323
</ScrollBar.Margin>
321324
<ScrollBar.Width>

0 commit comments

Comments
 (0)