Skip to content

Commit 532758c

Browse files
committed
text area style for TextBox
1 parent b24336a commit 532758c

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

MainDemo.Wpf/TextFields.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@
291291
<ComboBoxItem>Orange</ComboBoxItem>
292292
</ComboBox>
293293
<TextBlock Grid.Row="13" Grid.Column="1" Grid.ColumnSpan="3" Style="{StaticResource MaterialDesignHeadlineTextBlock}" Margin="0,0,0,16">Text field box</TextBlock>
294-
<TextBox Grid.Row="14" Grid.Column="1" Grid.ColumnSpan="3" Style="{StaticResource MaterialDesignTextFieldBoxTextBox}" materialDesign:HintAssist.Hint="Floating hint in a box" />
294+
<TextBox Grid.Row="14" Grid.Column="1" Grid.ColumnSpan="3" Style="{StaticResource MaterialDesignTextFieldBoxTextBox}"
295+
VerticalAlignment="Top" AcceptsReturn="True" TextWrapping="Wrap" MaxWidth="400" materialDesign:HintAssist.Hint="Floating hint in a box" />
296+
<TextBlock Grid.Row="13" Grid.Column="5" Grid.ColumnSpan="3" Style="{StaticResource MaterialDesignHeadlineTextBlock}" Margin="32,0,0,16">Text area box</TextBlock>
297+
<TextBox Grid.Row="14" Grid.Column="5" Grid.ColumnSpan="3" Style="{StaticResource MaterialDesignTextAreaTextBox}" Margin="32,0,0,0"
298+
VerticalAlignment="Top" Height="100" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" materialDesign:HintAssist.Hint="This is a text area" />
295299
</Grid>
296300
</UserControl>

MaterialDesignThemes.Wpf/TextFieldAssist.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public static Visibility GetDecorationVisibility(DependencyObject element)
6767
return (Visibility)element.GetValue(DecorationVisibilityProperty);
6868
}
6969

70+
/// <summary>
71+
/// Controls the visbility of the text field box.
72+
/// </summary>
7073
public static readonly DependencyProperty HasTextFieldBoxProperty = DependencyProperty.RegisterAttached(
7174
"HasTextFieldBox", typeof(bool), typeof(TextFieldAssist), new PropertyMetadata(false));
7275

@@ -80,6 +83,22 @@ public static bool GetHasTextFieldBox(DependencyObject element)
8083
return (bool)element.GetValue(HasTextFieldBoxProperty);
8184
}
8285

86+
/// <summary>
87+
/// Controls the visibility of the text field area box.
88+
/// </summary>
89+
public static readonly DependencyProperty HasTextAreaBoxProperty = DependencyProperty.RegisterAttached(
90+
"HasTextAreaBox", typeof(bool), typeof(TextFieldAssist), new PropertyMetadata(false));
91+
92+
public static void SetHasTextAreaBox(DependencyObject element, bool value)
93+
{
94+
element.SetValue(HasTextAreaBoxProperty, value);
95+
}
96+
97+
public static bool GetHasTextAreaBox(DependencyObject element)
98+
{
99+
return (bool)element.GetValue(HasTextAreaBoxProperty);
100+
}
101+
83102
/// <summary>
84103
/// Automatially inserts spelling suggestions into the text box context menu.
85104
/// </summary>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<Setter Property="BorderThickness" Value="0 0 0 1"/>
1616
<Setter Property="wpf:TextFieldAssist.TextBoxViewMargin" Value="0 0 0 0" />
1717
<Setter Property="Background" Value="Transparent"/>
18-
<Setter Property="CaretBrush" Value="{Binding RelativeSource={RelativeSource Self}, Path=BorderBrush}"/>
18+
<Setter Property="CaretBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
1919
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
2020
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
2121
<Setter Property="VerticalContentAlignment" Value="Bottom"/>
@@ -96,6 +96,7 @@
9696
<Setter TargetName="border" Property="Margin" Value="0 12 0 0" />
9797
</Trigger>
9898
<Trigger Property="wpf:TextFieldAssist.HasTextFieldBox" Value="True">
99+
<Setter Property="VerticalContentAlignment" Value="Top" />
99100
<Setter TargetName="textFieldBoxBorder" Property="Background" Value="{DynamicResource MaterialDesignTextFieldBoxBackground}" />
100101
<Setter TargetName="textFieldBoxBorder" Property="CornerRadius" Value="4" />
101102
<Setter TargetName="textFieldBoxBorder" Property="Padding" Value="0,8,0,0" />
@@ -105,6 +106,20 @@
105106
<Setter TargetName="Hint" Property="Margin" Value="0,0,0,16" />
106107
<Setter TargetName="PART_ContentHost" Property="Margin" Value="0,8,0,8" />
107108
</Trigger>
109+
<Trigger Property="wpf:TextFieldAssist.HasTextAreaBox" Value="True">
110+
<Setter Property="VerticalContentAlignment" Value="Top" />
111+
<Setter TargetName="textFieldBoxBorder" Property="Background" Value="Transparent" />
112+
<Setter TargetName="textFieldBoxBorder" Property="CornerRadius" Value="4" />
113+
<Setter TargetName="textFieldBoxBorder" Property="BorderThickness" Value="1" />
114+
<Setter TargetName="textFieldBoxBorder" Property="BorderBrush" Value="{DynamicResource MaterialDesignTextFieldBoxBackground}" />
115+
<Setter TargetName="textFieldBoxBorder" Property="Padding" Value="0,8,0,0" />
116+
<Setter TargetName="textFieldBoxBorder" Property="Margin" Value="-1" />
117+
<Setter TargetName="textFieldGrid" Property="Margin" Value="16,0,16,0" />
118+
<Setter TargetName="border" Property="BorderThickness" Value="0" />
119+
<Setter TargetName="Underline" Property="Visibility" Value="Collapsed" />
120+
<Setter TargetName="Hint" Property="Margin" Value="0,0,0,16" />
121+
<Setter TargetName="PART_ContentHost" Property="Margin" Value="0,8,0,8" />
122+
</Trigger>
108123
<Trigger Property="IsEnabled" Value="false">
109124
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
110125
</Trigger>
@@ -118,6 +133,23 @@
118133
<Setter Property="BorderBrush" Value="{DynamicResource ValidationErrorBrush}"/>
119134
<Setter TargetName="Underline" Property="Background" Value="{DynamicResource ValidationErrorBrush}"/>
120135
</Trigger>
136+
<MultiTrigger>
137+
<MultiTrigger.Conditions>
138+
<Condition Property="IsMouseOver" Value="True" />
139+
<Condition Property="wpf:TextFieldAssist.HasTextAreaBox" Value="True" />
140+
</MultiTrigger.Conditions>
141+
<Setter TargetName="textFieldBoxBorder" Property="Margin" Value="-2" />
142+
<Setter TargetName="textFieldBoxBorder" Property="BorderThickness" Value="2" />
143+
</MultiTrigger>
144+
<MultiTrigger>
145+
<MultiTrigger.Conditions>
146+
<Condition Property="IsKeyboardFocused" Value="True" />
147+
<Condition Property="wpf:TextFieldAssist.HasTextAreaBox" Value="True" />
148+
</MultiTrigger.Conditions>
149+
<Setter TargetName="textFieldBoxBorder" Property="Margin" Value="-2" />
150+
<Setter TargetName="textFieldBoxBorder" Property="BorderThickness" Value="2" />
151+
<Setter TargetName="textFieldBoxBorder" Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
152+
</MultiTrigger>
121153
</ControlTemplate.Triggers>
122154
</ControlTemplate>
123155
</Setter.Value>
@@ -137,9 +169,12 @@
137169
<Setter Property="wpf:HintAssist.IsFloating" Value="True"/>
138170
</Style>
139171

140-
<Style x:Key="MaterialDesignTextFieldBoxTextBox" TargetType="{x:Type TextBox}" BasedOn="{StaticResource MaterialDesignTextBox}">
172+
<Style x:Key="MaterialDesignTextFieldBoxTextBox" TargetType="{x:Type TextBox}" BasedOn="{StaticResource MaterialDesignFloatingHintTextBox}">
141173
<Setter Property="wpf:TextFieldAssist.HasTextFieldBox" Value="True" />
142-
<Setter Property="wpf:HintAssist.IsFloating" Value="True"/>
174+
</Style>
175+
176+
<Style x:Key="MaterialDesignTextAreaTextBox" TargetType="{x:Type TextBox}" BasedOn="{StaticResource MaterialDesignFloatingHintTextBox}">
177+
<Setter Property="wpf:TextFieldAssist.HasTextAreaBox" Value="True" />
143178
</Style>
144179

145180
</ResourceDictionary>

0 commit comments

Comments
 (0)