Skip to content

Commit e1d240d

Browse files
spiegelpKeboo
authored andcommitted
Property HighlightedBrush to change TextBox color (#1070)
* text field bottom line has 2dp height on hover * bottom line for text field box for inactive and hover * TextBox hover effect * hover and focus effects for text fields * applied new details of the Material Design specification to TextBox and PasswordBox * property HighlightedBrush to change the color of TextBox and PasswordBox issue #1025 * applied HighlightedBrush to ComboBox * API doc for HighlightedBrush * split HighlightedBrush into UnderlineHighlightedBrush and HighlightedForeground * renamed properties for text field hint and underline brushes * Removing default property setters * Adding example of setting the colors.
1 parent 18e12f3 commit e1d240d

File tree

6 files changed

+82
-23
lines changed

6 files changed

+82
-23
lines changed

MainDemo.Wpf/TextFields.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@
254254
<smtx:XamlDisplay Key="fields_18" Grid.Row="6" Grid.Column="1" Margin="0 12 0 0">
255255
<PasswordBox x:Name="FloatingPasswordBox"
256256
materialDesign:HintAssist.Hint="Floating Password"
257+
materialDesign:HintAssist.Foreground="Green"
258+
materialDesign:TextFieldAssist.UnderlineBrush="Green"
257259
Style="{StaticResource MaterialDesignFloatingHintPasswordBox}" />
258260
</smtx:XamlDisplay>
259261

MaterialDesignThemes.Wpf/HintAssist.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Windows;
2+
using System.Windows.Media;
23

34
namespace MaterialDesignThemes.Wpf
45
{
@@ -128,5 +129,31 @@ public static void SetHintOpacity(DependencyObject element, double value)
128129
}
129130

130131
#endregion
132+
133+
#region Brushes
134+
135+
/// <summary>
136+
/// The color for the text of a focused control.
137+
/// </summary>
138+
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.RegisterAttached(
139+
"Foreground", typeof(Brush), typeof(HintAssist), new PropertyMetadata(null));
140+
141+
/// <summary>
142+
/// Gets the color for the text of a focused control.
143+
/// </summary>
144+
public static Brush GetForeground(DependencyObject element)
145+
{
146+
return (Brush)element.GetValue(ForegroundProperty);
147+
}
148+
149+
/// <summary>
150+
/// Sets the color for the text of a focused control.
151+
/// </summary>
152+
public static void SetForeground(DependencyObject element, Brush value)
153+
{
154+
element.SetValue(ForegroundProperty, value);
155+
}
156+
157+
#endregion
131158
}
132159
}

MaterialDesignThemes.Wpf/TextFieldAssist.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Windows.Controls;
44
using System.Windows.Controls.Primitives;
55
using System.Windows.Documents;
6+
using System.Windows.Media;
67

78
namespace MaterialDesignThemes.Wpf
89
{
@@ -163,6 +164,28 @@ public static bool GetRippleOnFocusEnabled(DependencyObject element)
163164
return (bool)element.GetValue(RippleOnFocusEnabledProperty);
164165
}
165166

167+
/// <summary>
168+
/// The color for highlighting effects on the border of a text box.
169+
/// </summary>
170+
public static readonly DependencyProperty UnderlineBrushProperty = DependencyProperty.RegisterAttached(
171+
"UnderlineBrush", typeof(Brush), typeof(TextFieldAssist), new PropertyMetadata(null));
172+
173+
/// <summary>
174+
/// Sets the color for highlighting effects on the border of a text box.
175+
/// </summary>
176+
public static void SetUnderlineBrush(DependencyObject element, Brush value)
177+
{
178+
element.SetValue(UnderlineBrushProperty, value);
179+
}
180+
181+
/// <summary>
182+
/// Gets the color for highlighting effects on the border of a text box.
183+
/// </summary>
184+
public static Brush GetUnderlineBrush(DependencyObject element)
185+
{
186+
return (Brush)element.GetValue(UnderlineBrushProperty);
187+
}
188+
166189
/// <summary>
167190
/// Automatically inserts spelling suggestions into the text box context menu.
168191
/// </summary>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@
365365
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" />
366366
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true" />
367367
</MultiDataTrigger.Conditions>
368-
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
368+
<Setter Property="BorderBrush" Value="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" />
369369
</MultiDataTrigger>
370370
<Trigger Property="IsPressed" Value="true">
371-
<Setter TargetName="arrow" Property="Fill" Value="{DynamicResource PrimaryHueDarkBrush}" />
371+
<Setter TargetName="arrow" Property="Fill" Value="{DynamicResource PrimaryHueMidBrush}" />
372372
</Trigger>
373373
<Trigger Property="IsEnabled" Value="false">
374374
<Setter TargetName="arrow" Property="Fill" Value="{DynamicResource MaterialDesignCheckBoxDisabled}" />
@@ -451,7 +451,8 @@
451451
<wpf:Underline x:Name="Underline"
452452
Grid.ColumnSpan="2"
453453
IsActive="{Binding ElementName=PART_EditableTextBox, Path=IsKeyboardFocused}"
454-
Visibility="{Binding Path=(wpf:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}"/>
454+
Visibility="{Binding Path=(wpf:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}"
455+
Background="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource TemplatedParent}}" />
455456

456457
<wpf:ComboBoxPopup x:Name="PART_Popup"
457458
AllowsTransparency="true"
@@ -513,7 +514,7 @@
513514
<Condition Property="wpf:HintAssist.IsFloating" Value="True" />
514515
<Condition Property="IsKeyboardFocusWithin" Value="True" />
515516
</MultiTrigger.Conditions>
516-
<Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
517+
<Setter TargetName="Hint" Property="Foreground" Value="{Binding Path=(wpf:HintAssist.Foreground), RelativeSource={RelativeSource TemplatedParent}}" />
517518
<Setter TargetName="Hint" Property="HintOpacity" Value="1" />
518519
</MultiTrigger>
519520
<MultiTrigger>
@@ -522,23 +523,23 @@
522523
<Condition SourceName="Hint" Property="IsHintInFloatingPosition" Value="True" />
523524
<Condition Property="IsKeyboardFocusWithin" Value="True" />
524525
</MultiTrigger.Conditions>
525-
<Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
526+
<Setter TargetName="Hint" Property="Foreground" Value="{Binding Path=(wpf:HintAssist.Foreground), RelativeSource={RelativeSource TemplatedParent}}" />
526527
<Setter TargetName="Hint" Property="HintOpacity" Value="1" />
527528
</MultiTrigger>
528529
<MultiTrigger>
529530
<MultiTrigger.Conditions>
530531
<Condition SourceName="Hint" Property="IsContentNullOrEmpty" Value="False" />
531532
<Condition SourceName="PART_EditableTextBox" Property="IsKeyboardFocused" Value="True" />
532533
</MultiTrigger.Conditions>
533-
<Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
534+
<Setter TargetName="Hint" Property="Foreground" Value="{Binding Path=(wpf:HintAssist.Foreground), RelativeSource={RelativeSource TemplatedParent}}" />
534535
<Setter TargetName="Hint" Property="HintOpacity" Value="1" />
535536
</MultiTrigger>
536537
<MultiTrigger>
537538
<MultiTrigger.Conditions>
538539
<Condition SourceName="Hint" Property="IsContentNullOrEmpty" Value="False" />
539540
<Condition Property="IsDropDownOpen" Value="True" />
540541
</MultiTrigger.Conditions>
541-
<Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
542+
<Setter TargetName="Hint" Property="Foreground" Value="{Binding Path=(wpf:HintAssist.Foreground), RelativeSource={RelativeSource TemplatedParent}}" />
542543
<Setter TargetName="Hint" Property="HintOpacity" Value="1" />
543544
</MultiTrigger>
544545
<MultiTrigger>
@@ -568,8 +569,8 @@
568569
<Condition Property="IsMouseOver" Value="true" />
569570
<Condition Property="Validation.HasError" Value="false" />
570571
</MultiTrigger.Conditions>
571-
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
572-
<Setter TargetName="Underline" Property="Background" Value="{DynamicResource PrimaryHueMidBrush}"/>
572+
<Setter Property="BorderBrush" Value="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource Self}}" />
573+
<Setter TargetName="Underline" Property="Background" Value="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource TemplatedParent}}" />
573574
</MultiTrigger>
574575
</ControlTemplate.Triggers>
575576
</ControlTemplate>
@@ -593,13 +594,15 @@
593594
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
594595
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}"/>
595596
<Setter Property="wpf:TextFieldAssist.TextBoxViewMargin" Value="1 0 1 0" />
597+
<Setter Property="wpf:TextFieldAssist.UnderlineBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
598+
<Setter Property="wpf:HintAssist.Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
596599
<Setter Property="Template" Value="{StaticResource MaterialDesignFloatingHintComboBoxTemplate}" />
597600
<Style.Triggers>
598601
<Trigger Property="IsKeyboardFocused" Value="true">
599-
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
602+
<Setter Property="BorderBrush" Value="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource Self}}" />
600603
</Trigger>
601604
<Trigger Property="IsKeyboardFocusWithin" Value="true">
602-
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
605+
<Setter Property="BorderBrush" Value="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource Self}}" />
603606
</Trigger>
604607
<Trigger Property="IsEditable" Value="true">
605608
<Setter Property="IsTabStop" Value="false" />

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.PasswordBox.xaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<Setter Property="BorderThickness" Value="0 0 0 1"/>
1818
<Setter Property="wpf:TextFieldAssist.TextBoxViewMargin" Value="1 0 0 0" />
1919
<Setter Property="Background" Value="Transparent"/>
20-
<Setter Property="CaretBrush" Value="{Binding RelativeSource={RelativeSource Self}, Path=BorderBrush}"/>
20+
<Setter Property="CaretBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
2121
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
2222
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
2323
<Setter Property="VerticalContentAlignment" Value="Bottom"/>
@@ -26,6 +26,8 @@
2626
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
2727
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
2828
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}"/>
29+
<Setter Property="wpf:TextFieldAssist.UnderlineBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
30+
<Setter Property="wpf:HintAssist.Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
2931
<Setter Property="ContextMenu">
3032
<Setter.Value>
3133
<ContextMenu>
@@ -129,7 +131,8 @@
129131
X1="0" X2="{Binding ActualWidth, ElementName=border}" Y1="0" Y2="0"
130132
Stroke="{TemplateBinding BorderBrush}" Opacity="0.56" />
131133
<wpf:Underline x:Name="Underline" Visibility="{Binding Path=(wpf:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}"
132-
CornerRadius="{Binding Path=(wpf:TextFieldAssist.UnderlineCornerRadius), RelativeSource={RelativeSource TemplatedParent}}" />
134+
CornerRadius="{Binding Path=(wpf:TextFieldAssist.UnderlineCornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
135+
Background="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource TemplatedParent}}" />
133136
</Grid>
134137
</Border>
135138
</Grid>
@@ -139,7 +142,7 @@
139142
<Condition Property="wpf:HintAssist.IsFloating" Value="True" />
140143
<Condition Property="IsKeyboardFocused" Value="True" />
141144
</MultiTrigger.Conditions>
142-
<Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
145+
<Setter TargetName="Hint" Property="Foreground" Value="{Binding Path=(wpf:HintAssist.Foreground), RelativeSource={RelativeSource TemplatedParent}}" />
143146
<Setter TargetName="Hint" Property="HintOpacity" Value="1" />
144147
</MultiTrigger>
145148
<Trigger Property="wpf:HintAssist.IsFloating" Value="True">
@@ -206,7 +209,7 @@
206209
</MultiTrigger.Conditions>
207210
<Setter TargetName="passwordFieldBoxBorder" Property="Margin" Value="-2" />
208211
<Setter TargetName="passwordFieldBoxBorder" Property="BorderThickness" Value="2" />
209-
<Setter TargetName="passwordFieldBoxBorder" Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
212+
<Setter TargetName="passwordFieldBoxBorder" Property="BorderBrush" Value="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource TemplatedParent}}" />
210213
</MultiTrigger>
211214
<MultiTrigger>
212215
<MultiTrigger.Conditions>
@@ -222,7 +225,7 @@
222225
<Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="False" />
223226
<Condition Property="wpf:TextFieldAssist.NewSpecHighlightingEnabled" Value="False" />
224227
</MultiTrigger.Conditions>
225-
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
228+
<Setter Property="BorderBrush" Value="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource Self}}" />
226229
</MultiTrigger>
227230
<MultiTrigger>
228231
<MultiTrigger.Conditions>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<Setter Property="BorderThickness" Value="0 0 0 1"/>
1717
<Setter Property="wpf:TextFieldAssist.TextBoxViewMargin" Value="0 0 1 0" />
1818
<Setter Property="Background" Value="Transparent"/>
19-
<Setter Property="CaretBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
19+
<Setter Property="CaretBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
2020
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
2121
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
2222
<Setter Property="VerticalContentAlignment" Value="Bottom"/>
@@ -26,8 +26,8 @@
2626
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
2727
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}"/>
2828
<Setter Property="wpf:TextFieldAssist.IncludeSpellingSuggestions" Value="{Binding RelativeSource={RelativeSource Self}, Path=(SpellCheck.IsEnabled)}" />
29-
<Setter Property="wpf:TextFieldAssist.NewSpecHighlightingEnabled" Value="False" />
30-
<Setter Property="wpf:TextFieldAssist.RippleOnFocusEnabled" Value="False" />
29+
<Setter Property="wpf:TextFieldAssist.UnderlineBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
30+
<Setter Property="wpf:HintAssist.Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
3131
<!-- cludge the default context menu -->
3232
<Setter Property="ContextMenu">
3333
<Setter.Value>
@@ -133,7 +133,8 @@
133133
X1="0" X2="{Binding ActualWidth, ElementName=border}" Y1="0" Y2="0"
134134
Stroke="{TemplateBinding BorderBrush}" Opacity="0.56" />
135135
<wpf:Underline x:Name="Underline" Visibility="{Binding Path=(wpf:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}"
136-
CornerRadius="{Binding Path=(wpf:TextFieldAssist.UnderlineCornerRadius), RelativeSource={RelativeSource TemplatedParent}}" />
136+
CornerRadius="{Binding Path=(wpf:TextFieldAssist.UnderlineCornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
137+
Background="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource TemplatedParent}}" />
137138
</Grid>
138139
</Border>
139140
</Grid>
@@ -143,7 +144,7 @@
143144
<Condition Property="wpf:HintAssist.IsFloating" Value="True" />
144145
<Condition Property="IsKeyboardFocused" Value="True" />
145146
</MultiTrigger.Conditions>
146-
<Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
147+
<Setter TargetName="Hint" Property="Foreground" Value="{Binding Path=(wpf:HintAssist.Foreground), RelativeSource={RelativeSource TemplatedParent}}" />
147148
<Setter TargetName="Hint" Property="HintOpacity" Value="1" />
148149
</MultiTrigger>
149150
<Trigger Property="wpf:HintAssist.IsFloating" Value="True">
@@ -209,7 +210,7 @@
209210
</MultiTrigger.Conditions>
210211
<Setter TargetName="textFieldBoxBorder" Property="Margin" Value="-2" />
211212
<Setter TargetName="textFieldBoxBorder" Property="BorderThickness" Value="2" />
212-
<Setter TargetName="textFieldBoxBorder" Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
213+
<Setter TargetName="textFieldBoxBorder" Property="BorderBrush" Value="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource TemplatedParent}}" />
213214
</MultiTrigger>
214215
<MultiTrigger>
215216
<MultiTrigger.Conditions>
@@ -225,7 +226,7 @@
225226
<Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="False" />
226227
<Condition Property="wpf:TextFieldAssist.NewSpecHighlightingEnabled" Value="False" />
227228
</MultiTrigger.Conditions>
228-
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
229+
<Setter Property="BorderBrush" Value="{Binding Path=(wpf:TextFieldAssist.UnderlineBrush), RelativeSource={RelativeSource Self}}" />
229230
</MultiTrigger>
230231
<MultiTrigger>
231232
<MultiTrigger.Conditions>

0 commit comments

Comments
 (0)