Skip to content

Commit fedef9b

Browse files
committed
Refactored remaining TextBox extensions
1 parent ed27bed commit fedef9b

File tree

3 files changed

+56
-63
lines changed

3 files changed

+56
-63
lines changed

Microsoft.Toolkit.Uwp.UI/Extensions/TextBoxMask/TextBoxMask.cs renamed to Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Mask.Internals.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212

1313
namespace Microsoft.Toolkit.Uwp.UI
1414
{
15-
/// <summary>
16-
/// TextBox mask property allows a user to more easily enter fixed width text in TextBox control
17-
/// where you would like them to enter the data in a certain format
18-
/// </summary>
19-
public partial class TextBoxMask
15+
/// <inheritdoc cref="TextBoxExtensions"/>
16+
public static partial class TextBoxExtensions
2017
{
2118
private const string DefaultPlaceHolder = "_";
2219
private const char EscapeChar = '\\';
@@ -37,7 +34,7 @@ private static void InitTextBoxMask(DependencyObject d, DependencyPropertyChange
3734
textbox.TextChanging -= Textbox_TextChanging;
3835
textbox.Paste -= Textbox_Paste;
3936
textbox.Loaded -= Textbox_Loaded;
40-
textbox.GotFocus -= Textbox_GotFocus;
37+
textbox.GotFocus -= Textbox_GotFocus_Mask;
4138
textbox.Loaded += Textbox_Loaded;
4239
}
4340

@@ -145,13 +142,13 @@ private static void Textbox_Loaded(object sender, RoutedEventArgs e)
145142
textbox.TextChanging += Textbox_TextChanging;
146143
textbox.SelectionChanged += Textbox_SelectionChanged;
147144
textbox.Paste += Textbox_Paste;
148-
textbox.GotFocus += Textbox_GotFocus;
145+
textbox.GotFocus += Textbox_GotFocus_Mask;
149146
textbox.SetValue(OldTextProperty, textbox.Text);
150147
textbox.SetValue(DefaultDisplayTextProperty, displayText);
151148
textbox.SelectionStart = 0;
152149
}
153150

154-
private static void Textbox_GotFocus(object sender, RoutedEventArgs e)
151+
private static void Textbox_GotFocus_Mask(object sender, RoutedEventArgs e)
155152
{
156153
var textbox = (TextBox)sender;
157154
var mask = textbox?.GetValue(MaskProperty) as string;

Microsoft.Toolkit.Uwp.UI/Extensions/TextBoxMask/TextBoxMask.Properties.cs renamed to Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Mask.Properties.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,43 @@
44

55
using System.Collections.Generic;
66
using Windows.UI.Xaml;
7+
using Windows.UI.Xaml.Controls;
78

89
namespace Microsoft.Toolkit.Uwp.UI
910
{
10-
/// <summary>
11-
/// TextBox mask property allows a user to more easily enter fixed width text in TextBox control
12-
/// where you would like them to enter the data in a certain format
13-
/// </summary>
14-
public partial class TextBoxMask
11+
/// <inheritdoc cref="TextBoxExtensions"/>
12+
public static partial class TextBoxExtensions
1513
{
1614
/// <summary>
1715
/// Represents a mask/format for the textbox that the user must follow
1816
/// </summary>
19-
public static readonly DependencyProperty MaskProperty = DependencyProperty.RegisterAttached("Mask", typeof(string), typeof(TextBoxMask), new PropertyMetadata(null, InitTextBoxMask));
17+
public static readonly DependencyProperty MaskProperty = DependencyProperty.RegisterAttached("Mask", typeof(string), typeof(TextBoxExtensions), new PropertyMetadata(null, InitTextBoxMask));
2018

2119
/// <summary>
2220
/// Represents the mask place holder which represents the variable character that the user can edit in the textbox
2321
/// </summary>
24-
public static readonly DependencyProperty PlaceHolderProperty = DependencyProperty.RegisterAttached("PlaceHolder", typeof(string), typeof(TextBoxMask), new PropertyMetadata(DefaultPlaceHolder, InitTextBoxMask));
22+
public static readonly DependencyProperty PlaceHolderProperty = DependencyProperty.RegisterAttached("PlaceHolder", typeof(string), typeof(TextBoxExtensions), new PropertyMetadata(DefaultPlaceHolder, InitTextBoxMask));
2523

2624
/// <summary>
2725
/// Represents the custom mask that the user can create to add his own variable characters based on regex expression
2826
/// </summary>
29-
public static readonly DependencyProperty CustomMaskProperty = DependencyProperty.RegisterAttached("CustomMask", typeof(string), typeof(TextBoxMask), new PropertyMetadata(null, InitTextBoxMask));
27+
public static readonly DependencyProperty CustomMaskProperty = DependencyProperty.RegisterAttached("CustomMask", typeof(string), typeof(TextBoxExtensions), new PropertyMetadata(null, InitTextBoxMask));
3028

31-
private static readonly DependencyProperty RepresentationDictionaryProperty = DependencyProperty.RegisterAttached("RepresentationDictionary", typeof(Dictionary<char, string>), typeof(TextBoxMask), new PropertyMetadata(null));
32-
private static readonly DependencyProperty OldTextProperty = DependencyProperty.RegisterAttached("OldText", typeof(string), typeof(TextBoxMask), new PropertyMetadata(null));
33-
private static readonly DependencyProperty DefaultDisplayTextProperty = DependencyProperty.RegisterAttached("DefaultDisplayText", typeof(string), typeof(TextBoxMask), new PropertyMetadata(null));
34-
private static readonly DependencyProperty OldSelectionLengthProperty = DependencyProperty.RegisterAttached("OldSelectionLength", typeof(int), typeof(TextBoxMask), new PropertyMetadata(0));
35-
private static readonly DependencyProperty OldSelectionStartProperty = DependencyProperty.RegisterAttached("OldSelectionStart", typeof(int), typeof(TextBoxMask), new PropertyMetadata(0));
29+
private static readonly DependencyProperty RepresentationDictionaryProperty = DependencyProperty.RegisterAttached("RepresentationDictionary", typeof(Dictionary<char, string>), typeof(TextBoxExtensions), new PropertyMetadata(null));
30+
private static readonly DependencyProperty OldTextProperty = DependencyProperty.RegisterAttached("OldText", typeof(string), typeof(TextBoxExtensions), new PropertyMetadata(null));
31+
private static readonly DependencyProperty DefaultDisplayTextProperty = DependencyProperty.RegisterAttached("DefaultDisplayText", typeof(string), typeof(TextBoxExtensions), new PropertyMetadata(null));
32+
private static readonly DependencyProperty OldSelectionLengthProperty = DependencyProperty.RegisterAttached("OldSelectionLength", typeof(int), typeof(TextBoxExtensions), new PropertyMetadata(0));
33+
private static readonly DependencyProperty OldSelectionStartProperty = DependencyProperty.RegisterAttached("OldSelectionStart", typeof(int), typeof(TextBoxExtensions), new PropertyMetadata(0));
3634

37-
private static readonly DependencyProperty EscapedMaskProperty = DependencyProperty.RegisterAttached("EscapedMask", typeof(string), typeof(TextBoxMask), new PropertyMetadata(null));
38-
private static readonly DependencyProperty EscapedCharacterIndicesProperty = DependencyProperty.RegisterAttached("MaskEscapedCharacters", typeof(List<int>), typeof(TextBoxMask), new PropertyMetadata(null));
35+
private static readonly DependencyProperty EscapedMaskProperty = DependencyProperty.RegisterAttached("EscapedMask", typeof(string), typeof(TextBoxExtensions), new PropertyMetadata(null));
36+
private static readonly DependencyProperty EscapedCharacterIndicesProperty = DependencyProperty.RegisterAttached("MaskEscapedCharacters", typeof(List<int>), typeof(TextBoxExtensions), new PropertyMetadata(null));
3937

4038
/// <summary>
4139
/// Gets mask value
4240
/// </summary>
4341
/// <param name="obj">TextBox control</param>
4442
/// <returns>mask value</returns>
45-
public static string GetMask(DependencyObject obj)
43+
public static string GetMask(TextBox obj)
4644
{
4745
return (string)obj.GetValue(MaskProperty);
4846
}
@@ -52,7 +50,7 @@ public static string GetMask(DependencyObject obj)
5250
/// </summary>
5351
/// <param name="obj">TextBox Control</param>
5452
/// <param name="value">Mask Value</param>
55-
public static void SetMask(DependencyObject obj, string value)
53+
public static void SetMask(TextBox obj, string value)
5654
{
5755
obj.SetValue(MaskProperty, value);
5856
}
@@ -62,7 +60,7 @@ public static void SetMask(DependencyObject obj, string value)
6260
/// </summary>
6361
/// <param name="obj">TextBox control</param>
6462
/// <returns>placeholder value</returns>
65-
public static string GetPlaceHolder(DependencyObject obj)
63+
public static string GetPlaceHolder(TextBox obj)
6664
{
6765
return (string)obj.GetValue(PlaceHolderProperty);
6866
}
@@ -72,7 +70,7 @@ public static string GetPlaceHolder(DependencyObject obj)
7270
/// </summary>
7371
/// <param name="obj">TextBox Control</param>
7472
/// <param name="value">placeholder Value</param>
75-
public static void SetPlaceHolder(DependencyObject obj, string value)
73+
public static void SetPlaceHolder(TextBox obj, string value)
7674
{
7775
obj.SetValue(PlaceHolderProperty, value);
7876
}
@@ -82,7 +80,7 @@ public static void SetPlaceHolder(DependencyObject obj, string value)
8280
/// </summary>
8381
/// <param name="obj">TextBox control</param>
8482
/// <returns>CustomMask value</returns>
85-
public static string GetCustomMask(DependencyObject obj)
83+
public static string GetCustomMask(TextBox obj)
8684
{
8785
return (string)obj.GetValue(CustomMaskProperty);
8886
}
@@ -92,7 +90,7 @@ public static string GetCustomMask(DependencyObject obj)
9290
/// </summary>
9391
/// <param name="obj">TextBox Control</param>
9492
/// <param name="value">CustomMask Value</param>
95-
public static void SetCustomMask(DependencyObject obj, string value)
93+
public static void SetCustomMask(TextBox obj, string value)
9694
{
9795
obj.SetValue(CustomMaskProperty, value);
9896
}

0 commit comments

Comments
 (0)