Skip to content

Commit 154e19b

Browse files
authored
Fixing cursor disapear on right edge of text fields. (#1067)
Cleanup work with pattern matching.
1 parent 2ef2361 commit 154e19b

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

MaterialDesignThemes.Wpf/TextFieldAssist.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static Visibility GetDecorationVisibility(DependencyObject element)
6868
}
6969

7070
/// <summary>
71-
/// Controls the visbility of the filled text field.
71+
/// Controls the visibility of the filled text field.
7272
/// </summary>
7373
public static readonly DependencyProperty HasFilledTextFieldProperty = DependencyProperty.RegisterAttached(
7474
"HasFilledTextField", typeof(bool), typeof(TextFieldAssist), new PropertyMetadata(false));
@@ -116,7 +116,7 @@ public static CornerRadius GetTextFieldCornerRadius(DependencyObject element)
116116
}
117117

118118
/// <summary>
119-
/// Controls the corner radius of the bottom line of the surroundig box.
119+
/// Controls the corner radius of the bottom line of the surrounding box.
120120
/// </summary>
121121
public static readonly DependencyProperty UnderlineCornerRadiusProperty = DependencyProperty.RegisterAttached(
122122
"UnderlineCornerRadius", typeof(CornerRadius), typeof(TextFieldAssist), new PropertyMetadata(new CornerRadius(0.0)));
@@ -164,7 +164,7 @@ public static bool GetRippleOnFocusEnabled(DependencyObject element)
164164
}
165165

166166
/// <summary>
167-
/// Automatially inserts spelling suggestions into the text box context menu.
167+
/// Automatically inserts spelling suggestions into the text box context menu.
168168
/// </summary>
169169
public static readonly DependencyProperty IncludeSpellingSuggestionsProperty = DependencyProperty.RegisterAttached(
170170
"IncludeSpellingSuggestions", typeof(bool), typeof(TextFieldAssist), new PropertyMetadata(default(bool), IncludeSpellingSuggestionsChanged));
@@ -181,8 +181,7 @@ public static bool GetIncludeSpellingSuggestions(TextBoxBase element)
181181

182182
private static void IncludeSpellingSuggestionsChanged(DependencyObject element, DependencyPropertyChangedEventArgs e)
183183
{
184-
var textBox = element as TextBoxBase;
185-
if (textBox != null)
184+
if (element is TextBoxBase textBox)
186185
{
187186
if ((bool)e.NewValue)
188187
{
@@ -262,13 +261,12 @@ private static void TextBoxOnContextMenuOpening(object sender, ContextMenuEventA
262261

263262
private static SpellingError GetSpellingError(TextBoxBase textBoxBase)
264263
{
265-
var textBox = textBoxBase as TextBox;
266-
if (textBox != null)
264+
if (textBoxBase is TextBox textBox)
267265
{
268266
return textBox.GetSpellingError(textBox.CaretIndex);
269267
}
270-
var richTextBox = textBoxBase as RichTextBox;
271-
if (richTextBox != null)
268+
269+
if (textBoxBase is RichTextBox richTextBox)
272270
{
273271
return richTextBox.GetSpellingError(richTextBox.CaretPosition);
274272
}
@@ -308,8 +306,7 @@ private static void ApplyTextBoxViewMargin(Control textBox, Thickness margin)
308306
return;
309307
}
310308

311-
var frameworkElement = (textBox.Template.FindName("PART_ContentHost", textBox) as ScrollViewer)?.Content as FrameworkElement;
312-
if (frameworkElement != null)
309+
if ((textBox.Template.FindName("PART_ContentHost", textBox) as ScrollViewer)?.Content is FrameworkElement frameworkElement)
313310
{
314311
frameworkElement.Margin = margin;
315312
}
@@ -324,8 +321,7 @@ private static void TextBoxViewMarginPropertyChangedCallback(
324321
DependencyObject dependencyObject,
325322
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
326323
{
327-
var box = dependencyObject as Control; //could be a text box or password box
328-
if (box == null)
324+
if (!(dependencyObject is Control box))
329325
{
330326
return;
331327
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
1515
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}" />
1616
<Setter Property="BorderThickness" Value="0 0 0 1"/>
17-
<Setter Property="wpf:TextFieldAssist.TextBoxViewMargin" Value="0 0 0 0" />
17+
<Setter Property="wpf:TextFieldAssist.TextBoxViewMargin" Value="0 0 1 0" />
1818
<Setter Property="Background" Value="Transparent"/>
1919
<Setter Property="CaretBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
2020
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>

0 commit comments

Comments
 (0)