Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,34 @@
</Grid.RowDefinitions>

<TextBox Name="AlphaTextBox"
ui:TextBoxMask.Mask="9a9a-a9a*"
ui:TextBoxExtensions.Mask="9a9a-a9a*"
Header="Text box with Mask 9a9a-a9a* (9 allows from 0 to 9, a allow from a to Z and * allows both a and 9)"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource MaskedTextBoxStyle}"
Text="TextBoxMask" />
Text="TextBoxMask" />

<TextBox Grid.Row="1"
ui:TextBoxMask.Mask="+1999-9999"
ui:TextBoxMask.PlaceHolder=" "
ui:TextBoxExtensions.Mask="+1999-9999"
ui:TextBoxExtensions.MaskPlaceholder=" "
Header="Text box with Mask +1999-9999 and placeHolder as space (placeholder represents the characters the user can change on runtime)"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource MaskedTextBoxStyle}" />

<TextBox Grid.Row="2"
ui:TextBoxMask.Mask="+\964 799 999 9999"
ui:TextBoxExtensions.Mask="+\964 799 999 9999"
Header="Text box with Mask +964 799 999 9999 (Notice how we escape the first 9 with a backslash)"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource MaskedTextBoxStyle}" />

<TextBox Grid.Row="3"
ui:TextBoxMask.Mask="99\\99\\9999"
ui:TextBoxExtensions.Mask="99\\99\\9999"
Header="Text box with Mask 99\99\9999 (You can escape a backslash with another backslash)"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource MaskedTextBoxStyle}" />

<TextBox Grid.Row="4"
ui:TextBoxMask.CustomMask="5:[1-5],c:[a-c]"
ui:TextBoxMask.Mask="a5c-5c*9"
ui:TextBoxExtensions.CustomMask="5:[1-5],c:[a-c]"
ui:TextBoxExtensions.Mask="a5c-5c*9"
Header="Text box with CustomMask in case you want to define your own variable character like a, 9 and *. Mask: a5c-5c*9, 5: [1-5], c: [a-c]"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource MaskedTextBoxStyle}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<TextBox ui:TextBoxExtensions.Mask="9a9a--a9a*"/>

<TextBox ui:TextBoxExtensions.Mask="+1999-9999"
ui:TextBoxExtensions.PlaceHolder=" " />
ui:TextBoxExtensions.MaskPlaceholder=" " />

<TextBox ui:TextBoxExtensions.Mask="+\964 799 999 9999"
ui:TextBoxExtensions.PlaceHolder=" " />
ui:TextBoxExtensions.MaskPlaceholder=" " />

<TextBox ui:TextBoxExtensions.CustomMask="5:[1-5],c:[a-c]"
ui:TextBoxExtensions.Mask="a5c-5c*9" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,70 +34,70 @@

<StackPanel Margin="10,10,10,0">
<TextBox Name="PhoneNumberValidator"
ui:TextBoxRegex.Regex="^\s*\+?\s*([0-9][\s-]*){9,}$"
ui:TextBoxExtensions.Regex="^\s*\+?\s*([0-9][\s-]*){9,}$"
Header="Text box with Regex extension for phone number, validation occurs on TextChanged"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource TextBoxRegexStyle}" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Is Valid: " />
<TextBlock Text="{Binding (ui:TextBoxRegex.IsValid), ElementName=PhoneNumberValidator, Converter={StaticResource StringFormatConverter}}" />
<TextBlock Text="{Binding (ui:TextBoxExtensions.IsValid), ElementName=PhoneNumberValidator, Converter={StaticResource StringFormatConverter}}" />
</StackPanel>

</StackPanel>

<StackPanel Grid.Row="1"
Margin="10,10,10,0">
Margin="10,10,10,0">
<TextBox Name="CharactValidator"
ui:TextBoxRegex.ValidationMode="Dynamic"
ui:TextBoxRegex.ValidationType="Characters"
ui:TextBoxExtensions.ValidationMode="Dynamic"
ui:TextBoxExtensions.ValidationType="Characters"
Header="Text box with ValidationType=Characters, validation occurs at input with ValidationMode=Dynamic and clear only single character when value is invalid"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource TextBoxRegexStyle}"
Text="abcdef" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Is Valid: " />
<TextBlock Text="{Binding (ui:TextBoxRegex.IsValid), ElementName=CharactValidator, Converter={StaticResource StringFormatConverter}}" />
<TextBlock Text="{Binding (ui:TextBoxExtensions.IsValid), ElementName=CharactValidator, Converter={StaticResource StringFormatConverter}}" />
</StackPanel>
</StackPanel>

<StackPanel Grid.Row="2"
Margin="10,10,10,0">
Margin="10,10,10,0">
<TextBox Name="EmailValidator"
ui:TextBoxRegex.ValidationType="Email"
ui:TextBoxExtensions.ValidationType="Email"
Header="Text box with ValidationType=Email, validation occurs on TextChanged"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource TextBoxRegexStyle}" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Is Valid: " />
<TextBlock Text="{Binding (ui:TextBoxRegex.IsValid), ElementName=EmailValidator, Converter={StaticResource StringFormatConverter}}" />
<TextBlock Text="{Binding (ui:TextBoxExtensions.IsValid), ElementName=EmailValidator, Converter={StaticResource StringFormatConverter}}" />
</StackPanel>
</StackPanel>

<StackPanel Grid.Row="3"
Margin="10,10,10,0">
<TextBox Name="DecimalValidatorForce"
ui:TextBoxRegex.ValidationMode="Forced"
ui:TextBoxRegex.ValidationType="Decimal"
ui:TextBoxExtensions.ValidationMode="Forced"
ui:TextBoxExtensions.ValidationType="Decimal"
Header="Text box with ValidationType=Decimal, validation occurs on TextChanged and force occurs on lose focus with ValidationMode=Force (333,111 or 333.111)"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource TextBoxRegexStyle}" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Is Valid: " />
<TextBlock Text="{Binding (ui:TextBoxRegex.IsValid), ElementName=DecimalValidatorForce, Converter={StaticResource StringFormatConverter}}" />
<TextBlock Text="{Binding (ui:TextBoxExtensions.IsValid), ElementName=DecimalValidatorForce, Converter={StaticResource StringFormatConverter}}" />
</StackPanel>
</StackPanel>

<StackPanel Grid.Row="4"
Margin="10,10,10,0">
<TextBox Name="NumberValidatorDynamic"
ui:TextBoxRegex.ValidationMode="Dynamic"
ui:TextBoxRegex.ValidationType="Number"
ui:TextBoxExtensions.ValidationMode="Dynamic"
ui:TextBoxExtensions.ValidationType="Number"
Header="Text box with ValidationType=Number, validation occurs at input with ValidationMode=Dynamic and clear only single character when value is invalid"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource TextBoxRegexStyle}" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Is Valid: " />
<TextBlock Text="{Binding (ui:TextBoxRegex.IsValid), ElementName=NumberValidatorDynamic, Converter={StaticResource StringFormatConverter}}" />
<TextBlock Text="{Binding (ui:TextBoxExtensions.IsValid), ElementName=NumberValidatorDynamic, Converter={StaticResource StringFormatConverter}}" />
</StackPanel>
</StackPanel>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Windows.UI.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace Microsoft.Toolkit.Uwp.UI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static void Textbox_Loaded(object sender, RoutedEventArgs e)
return;
}

var placeHolderValue = textbox.GetValue(PlaceHolderProperty) as string;
var placeHolderValue = textbox.GetValue(MaskPlaceholderProperty) as string;
if (string.IsNullOrEmpty(placeHolderValue))
{
throw new ArgumentException("PlaceHolder can't be null or empty");
Expand Down Expand Up @@ -152,7 +152,7 @@ private static void Textbox_GotFocus_Mask(object sender, RoutedEventArgs e)
{
var textbox = (TextBox)sender;
var mask = textbox?.GetValue(MaskProperty) as string;
var placeHolderValue = textbox?.GetValue(PlaceHolderProperty) as string;
var placeHolderValue = textbox?.GetValue(MaskPlaceholderProperty) as string;
var representationDictionary = textbox?.GetValue(RepresentationDictionaryProperty) as Dictionary<char, string>;
if (string.IsNullOrWhiteSpace(mask) ||
representationDictionary == null ||
Expand Down Expand Up @@ -194,7 +194,7 @@ private static async void Textbox_Paste(object sender, TextControlPasteEventArgs
var textbox = (TextBox)sender;
var mask = textbox.GetValue(MaskProperty) as string;
var representationDictionary = textbox?.GetValue(RepresentationDictionaryProperty) as Dictionary<char, string>;
var placeHolderValue = textbox.GetValue(PlaceHolderProperty) as string;
var placeHolderValue = textbox.GetValue(MaskPlaceholderProperty) as string;
if (string.IsNullOrWhiteSpace(mask) ||
representationDictionary == null ||
string.IsNullOrEmpty(placeHolderValue))
Expand Down Expand Up @@ -262,7 +262,7 @@ private static void Textbox_TextChanging(TextBox textbox, TextBoxTextChangingEve
var escapedChars = textbox.GetValue(EscapedCharacterIndicesProperty) as List<int>;

var representationDictionary = textbox.GetValue(RepresentationDictionaryProperty) as Dictionary<char, string>;
var placeHolderValue = textbox?.GetValue(PlaceHolderProperty) as string;
var placeHolderValue = textbox?.GetValue(MaskPlaceholderProperty) as string;
var oldText = textbox.GetValue(OldTextProperty) as string;
var oldSelectionStart = (int)textbox.GetValue(OldSelectionStartProperty);
var oldSelectionLength = (int)textbox.GetValue(OldSelectionLengthProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static partial class TextBoxExtensions
/// <summary>
/// Represents the mask place holder which represents the variable character that the user can edit in the textbox
/// </summary>
public static readonly DependencyProperty PlaceHolderProperty = DependencyProperty.RegisterAttached("PlaceHolder", typeof(string), typeof(TextBoxExtensions), new PropertyMetadata(DefaultPlaceHolder, InitTextBoxMask));
public static readonly DependencyProperty MaskPlaceholderProperty = DependencyProperty.RegisterAttached("MaskPlaceholder", typeof(string), typeof(TextBoxExtensions), new PropertyMetadata(DefaultPlaceHolder, InitTextBoxMask));

/// <summary>
/// Represents the custom mask that the user can create to add his own variable characters based on regex expression
Expand Down Expand Up @@ -60,19 +60,19 @@ public static void SetMask(TextBox obj, string value)
/// </summary>
/// <param name="obj">TextBox control</param>
/// <returns>placeholder value</returns>
public static string GetPlaceHolder(TextBox obj)
public static string GetMaskPlaceholder(TextBox obj)
{
return (string)obj.GetValue(PlaceHolderProperty);
return (string)obj.GetValue(MaskPlaceholderProperty);
}

/// <summary>
/// Sets placeholder property which represents the variable character that the user can edit in the textbox
/// </summary>
/// <param name="obj">TextBox Control</param>
/// <param name="value">placeholder Value</param>
public static void SetPlaceHolder(TextBox obj, string value)
public static void SetMaskPlaceholder(TextBox obj, string value)
{
obj.SetValue(PlaceHolderProperty, value);
obj.SetValue(MaskPlaceholderProperty, value);
}

/// <summary>
Expand Down