Skip to content

Commit 0dc871f

Browse files
Merge branch 'master' into fix/tabbedcommandbar_SCTRB
2 parents 6c06695 + 1d70e62 commit 0dc871f

File tree

10 files changed

+85
-78
lines changed

10 files changed

+85
-78
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TextBoxMask/TextBoxMask.bind

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,34 @@
3333
</Grid.RowDefinitions>
3434

3535
<TextBox Name="AlphaTextBox"
36-
ui:TextBoxMask.Mask="9a9a-a9a*"
36+
ui:TextBoxExtensions.Mask="9a9a-a9a*"
3737
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)"
3838
HeaderTemplate="{StaticResource HeaderTemplate}"
3939
Style="{StaticResource MaskedTextBoxStyle}"
40-
Text="TextBoxMask" />
40+
Text="TextBoxMask" />
4141

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

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

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

6161
<TextBox Grid.Row="4"
62-
ui:TextBoxMask.CustomMask="5:[1-5],c:[a-c]"
63-
ui:TextBoxMask.Mask="a5c-5c*9"
62+
ui:TextBoxExtensions.CustomMask="5:[1-5],c:[a-c]"
63+
ui:TextBoxExtensions.Mask="a5c-5c*9"
6464
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]"
6565
HeaderTemplate="{StaticResource HeaderTemplate}"
6666
Style="{StaticResource MaskedTextBoxStyle}" />

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TextBoxMask/TextBoxMaskPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<TextBox ui:TextBoxExtensions.Mask="9a9a--a9a*"/>
1212

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

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

1919
<TextBox ui:TextBoxExtensions.CustomMask="5:[1-5],c:[a-c]"
2020
ui:TextBoxExtensions.Mask="a5c-5c*9" />

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TextBoxRegex/TextBoxRegex.bind

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,70 +34,70 @@
3434

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

4646
</StackPanel>
4747

4848
<StackPanel Grid.Row="1"
49-
Margin="10,10,10,0">
49+
Margin="10,10,10,0">
5050
<TextBox Name="CharactValidator"
51-
ui:TextBoxRegex.ValidationMode="Dynamic"
52-
ui:TextBoxRegex.ValidationType="Characters"
51+
ui:TextBoxExtensions.ValidationMode="Dynamic"
52+
ui:TextBoxExtensions.ValidationType="Characters"
5353
Header="Text box with ValidationType=Characters, validation occurs at input with ValidationMode=Dynamic and clear only single character when value is invalid"
5454
HeaderTemplate="{StaticResource HeaderTemplate}"
5555
Style="{StaticResource TextBoxRegexStyle}"
5656
Text="abcdef" />
5757
<StackPanel Orientation="Horizontal">
5858
<TextBlock Text="Is Valid: " />
59-
<TextBlock Text="{Binding (ui:TextBoxRegex.IsValid), ElementName=CharactValidator, Converter={StaticResource StringFormatConverter}}" />
59+
<TextBlock Text="{Binding (ui:TextBoxExtensions.IsValid), ElementName=CharactValidator, Converter={StaticResource StringFormatConverter}}" />
6060
</StackPanel>
6161
</StackPanel>
6262

6363
<StackPanel Grid.Row="2"
64-
Margin="10,10,10,0">
64+
Margin="10,10,10,0">
6565
<TextBox Name="EmailValidator"
66-
ui:TextBoxRegex.ValidationType="Email"
66+
ui:TextBoxExtensions.ValidationType="Email"
6767
Header="Text box with ValidationType=Email, validation occurs on TextChanged"
6868
HeaderTemplate="{StaticResource HeaderTemplate}"
6969
Style="{StaticResource TextBoxRegexStyle}" />
7070
<StackPanel Orientation="Horizontal">
7171
<TextBlock Text="Is Valid: " />
72-
<TextBlock Text="{Binding (ui:TextBoxRegex.IsValid), ElementName=EmailValidator, Converter={StaticResource StringFormatConverter}}" />
72+
<TextBlock Text="{Binding (ui:TextBoxExtensions.IsValid), ElementName=EmailValidator, Converter={StaticResource StringFormatConverter}}" />
7373
</StackPanel>
7474
</StackPanel>
7575

7676
<StackPanel Grid.Row="3"
7777
Margin="10,10,10,0">
7878
<TextBox Name="DecimalValidatorForce"
79-
ui:TextBoxRegex.ValidationMode="Forced"
80-
ui:TextBoxRegex.ValidationType="Decimal"
79+
ui:TextBoxExtensions.ValidationMode="Forced"
80+
ui:TextBoxExtensions.ValidationType="Decimal"
8181
Header="Text box with ValidationType=Decimal, validation occurs on TextChanged and force occurs on lose focus with ValidationMode=Force (333,111 or 333.111)"
8282
HeaderTemplate="{StaticResource HeaderTemplate}"
8383
Style="{StaticResource TextBoxRegexStyle}" />
8484
<StackPanel Orientation="Horizontal">
8585
<TextBlock Text="Is Valid: " />
86-
<TextBlock Text="{Binding (ui:TextBoxRegex.IsValid), ElementName=DecimalValidatorForce, Converter={StaticResource StringFormatConverter}}" />
86+
<TextBlock Text="{Binding (ui:TextBoxExtensions.IsValid), ElementName=DecimalValidatorForce, Converter={StaticResource StringFormatConverter}}" />
8787
</StackPanel>
8888
</StackPanel>
8989

9090
<StackPanel Grid.Row="4"
9191
Margin="10,10,10,0">
9292
<TextBox Name="NumberValidatorDynamic"
93-
ui:TextBoxRegex.ValidationMode="Dynamic"
94-
ui:TextBoxRegex.ValidationType="Number"
93+
ui:TextBoxExtensions.ValidationMode="Dynamic"
94+
ui:TextBoxExtensions.ValidationType="Number"
9595
Header="Text box with ValidationType=Number, validation occurs at input with ValidationMode=Dynamic and clear only single character when value is invalid"
9696
HeaderTemplate="{StaticResource HeaderTemplate}"
9797
Style="{StaticResource TextBoxRegexStyle}" />
9898
<StackPanel Orientation="Horizontal">
9999
<TextBlock Text="Is Valid: " />
100-
<TextBlock Text="{Binding (ui:TextBoxRegex.IsValid), ElementName=NumberValidatorDynamic, Converter={StaticResource StringFormatConverter}}" />
100+
<TextBlock Text="{Binding (ui:TextBoxExtensions.IsValid), ElementName=NumberValidatorDynamic, Converter={StaticResource StringFormatConverter}}" />
101101
</StackPanel>
102102
</StackPanel>
103103

Microsoft.Toolkit.Uwp.UI.Animations/Extensions/StoryboardAnimations.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ public static Task BeginAsync(this Storyboard storyboard)
2323
{
2424
TaskCompletionSource<object?> taskCompletionSource = new TaskCompletionSource<object?>();
2525

26-
storyboard.Completed += (_, _) => taskCompletionSource.SetResult(null);
26+
void OnCompleted(object sender, object e)
27+
{
28+
((Storyboard)sender).Completed -= OnCompleted;
29+
30+
taskCompletionSource.SetResult(null);
31+
}
32+
33+
storyboard.Completed += OnCompleted;
2734

2835
storyboard.Begin();
2936

Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/SurfaceDialOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Windows.UI.Input;
66
using Windows.UI.Xaml;
77
using Windows.UI.Xaml.Controls;
8-
using Windows.UI.Xaml.Input;
98

109
namespace Microsoft.Toolkit.Uwp.UI
1110
{

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private static void Textbox_Loaded(object sender, RoutedEventArgs e)
4949
return;
5050
}
5151

52-
var placeHolderValue = textbox.GetValue(PlaceHolderProperty) as string;
52+
var placeHolderValue = textbox.GetValue(MaskPlaceholderProperty) as string;
5353
if (string.IsNullOrEmpty(placeHolderValue))
5454
{
5555
throw new ArgumentException("PlaceHolder can't be null or empty");
@@ -152,7 +152,7 @@ private static void Textbox_GotFocus_Mask(object sender, RoutedEventArgs e)
152152
{
153153
var textbox = (TextBox)sender;
154154
var mask = textbox?.GetValue(MaskProperty) as string;
155-
var placeHolderValue = textbox?.GetValue(PlaceHolderProperty) as string;
155+
var placeHolderValue = textbox?.GetValue(MaskPlaceholderProperty) as string;
156156
var representationDictionary = textbox?.GetValue(RepresentationDictionaryProperty) as Dictionary<char, string>;
157157
if (string.IsNullOrWhiteSpace(mask) ||
158158
representationDictionary == null ||
@@ -194,7 +194,7 @@ private static async void Textbox_Paste(object sender, TextControlPasteEventArgs
194194
var textbox = (TextBox)sender;
195195
var mask = textbox.GetValue(MaskProperty) as string;
196196
var representationDictionary = textbox?.GetValue(RepresentationDictionaryProperty) as Dictionary<char, string>;
197-
var placeHolderValue = textbox.GetValue(PlaceHolderProperty) as string;
197+
var placeHolderValue = textbox.GetValue(MaskPlaceholderProperty) as string;
198198
if (string.IsNullOrWhiteSpace(mask) ||
199199
representationDictionary == null ||
200200
string.IsNullOrEmpty(placeHolderValue))
@@ -262,7 +262,7 @@ private static void Textbox_TextChanging(TextBox textbox, TextBoxTextChangingEve
262262
var escapedChars = textbox.GetValue(EscapedCharacterIndicesProperty) as List<int>;
263263

264264
var representationDictionary = textbox.GetValue(RepresentationDictionaryProperty) as Dictionary<char, string>;
265-
var placeHolderValue = textbox?.GetValue(PlaceHolderProperty) as string;
265+
var placeHolderValue = textbox?.GetValue(MaskPlaceholderProperty) as string;
266266
var oldText = textbox.GetValue(OldTextProperty) as string;
267267
var oldSelectionStart = (int)textbox.GetValue(OldSelectionStartProperty);
268268
var oldSelectionLength = (int)textbox.GetValue(OldSelectionLengthProperty);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static partial class TextBoxExtensions
1919
/// <summary>
2020
/// Represents the mask place holder which represents the variable character that the user can edit in the textbox
2121
/// </summary>
22-
public static readonly DependencyProperty PlaceHolderProperty = DependencyProperty.RegisterAttached("PlaceHolder", typeof(string), typeof(TextBoxExtensions), new PropertyMetadata(DefaultPlaceHolder, InitTextBoxMask));
22+
public static readonly DependencyProperty MaskPlaceholderProperty = DependencyProperty.RegisterAttached("MaskPlaceholder", typeof(string), typeof(TextBoxExtensions), new PropertyMetadata(DefaultPlaceHolder, InitTextBoxMask));
2323

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

6868
/// <summary>
6969
/// Sets placeholder property which represents the variable character that the user can edit in the textbox
7070
/// </summary>
7171
/// <param name="obj">TextBox Control</param>
7272
/// <param name="value">placeholder Value</param>
73-
public static void SetPlaceHolder(TextBox obj, string value)
73+
public static void SetMaskPlaceholder(TextBox obj, string value)
7474
{
75-
obj.SetValue(PlaceHolderProperty, value);
75+
obj.SetValue(MaskPlaceholderProperty, value);
7676
}
7777

7878
/// <summary>

UnitTests/UnitTests.UWP/Extensions/Test_PointExtensions.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,51 @@ public class Test_PointExtensions
1313
{
1414
[TestCategory("PointExtensions")]
1515
[TestMethod]
16-
[DataRow(0d, 0d, 0, 0)]
17-
[DataRow(0d, 0d, 22, 6.89d)]
16+
[DataRow(0d, 0d, 0d, 0d)]
17+
[DataRow(0d, 0d, 22d, 6.89d)]
1818
[DataRow(3.14d, 6.55f, 3838d, 3.24724928d)]
19-
[DataRow(double.MinValue, double.Epsilon, 22, 0.3248d)]
20-
public static void Test_PointExtensions_ToRect_FromWidthHeight(double width, double height, int x, int y)
19+
[DataRow(double.MaxValue / 2, double.Epsilon, 22d, 0.3248d)]
20+
public void Test_PointExtensions_ToRect_FromWidthHeight(double width, double height, double x, double y)
2121
{
22-
Point p = new Point(x, y);
22+
Point p = new(x, y);
2323
Rect
2424
a = p.ToRect(width, height),
25-
b = new Rect(x, y, width, height);
25+
b = new(x, y, width, height);
2626

2727
Assert.AreEqual(a, b);
2828
}
2929

3030
[TestCategory("SizeExtensions")]
3131
[TestMethod]
32-
[DataRow(0d, 0d, 0, 0)]
33-
[DataRow(0d, 0d, 22, 6.89d)]
32+
[DataRow(0d, 0d, 0d, 0d)]
33+
[DataRow(0d, 0d, 22d, 6.89d)]
3434
[DataRow(3.14d, 6.55f, 3838d, 3.24724928d)]
35-
[DataRow(double.MinValue, double.Epsilon, 22, 0.3248d)]
36-
public static void Test_PointExtensions_ToRect_FromPoint(double width, double height, int x, int y)
35+
[DataRow(double.MaxValue / 2, double.Epsilon, 22, 0.3248d)]
36+
public void Test_PointExtensions_ToRect_FromPoint(double width, double height, double x, double y)
3737
{
3838
Point
39-
p1 = new Point(x, y),
40-
p2 = new Point(x + width, y + height);
39+
p1 = new(x, y),
40+
p2 = new(x + width, y + height);
4141
Rect
4242
a = p1.ToRect(p2),
43-
b = new Rect(p1, p2);
43+
b = new(p1, p2);
4444

4545
Assert.AreEqual(a, b);
4646
}
4747

4848
[TestCategory("SizeExtensions")]
4949
[TestMethod]
50-
[DataRow(0d, 0d, 0, 0)]
51-
[DataRow(0d, 0d, 22, 6.89d)]
50+
[DataRow(0d, 0d, 0d, 0d)]
51+
[DataRow(0d, 0d, 22d, 6.89d)]
5252
[DataRow(3.14d, 6.55f, 3838d, 3.24724928d)]
53-
[DataRow(double.MinValue, double.Epsilon, 22, 0.3248d)]
54-
public static void Test_PointExtensions_ToRect_FromSize(double width, double height, int x, int y)
53+
[DataRow(double.MaxValue / 2, double.Epsilon, 22, 0.3248d)]
54+
public void Test_PointExtensions_ToRect_FromSize(double width, double height, double x, double y)
5555
{
56-
Point p = new Point(x, y);
57-
Size s = new Size(width, height);
56+
Point p = new(x, y);
57+
Size s = new(width, height);
5858
Rect
5959
a = p.ToRect(s),
60-
b = new Rect(p, s);
60+
b = new(p, s);
6161

6262
Assert.AreEqual(a, b);
6363
}

UnitTests/UnitTests.UWP/Extensions/Test_RectExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ public class Test_RectExtensions
2626
[DataRow(0, 0, 2, 2, -2, 2, 2, 2, true)]// Left bottom corner(0, 2) intersection.
2727
[DataRow(0, 0, 2, 2, 3, 0, 2, 2, false)]// No intersection.
2828
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1117:Parameters should be on same line or separate lines", Justification = "Put the parameters of the same rectangle on the same line is clearer.")]
29-
public static void Test_RectExtensions_IntersectsWith(
29+
public void Test_RectExtensions_IntersectsWith(
3030
double rect1X, double rect1Y, double rect1Width, double rect1Height,
3131
double rect2X, double rect2Y, double rect2Width, double rect2Height,
3232
bool shouldIntersectsWith)
3333
{
34-
var rect1 = new Rect(rect1X, rect1Y, rect1Width, rect1Height);
35-
var rect2 = new Rect(rect2X, rect2Y, rect2Width, rect2Height);
36-
var isIntersectsWith = rect1.IntersectsWith(rect2);
34+
Rect rect1 = new(rect1X, rect1Y, rect1Width, rect1Height);
35+
Rect rect2 = new(rect2X, rect2Y, rect2Width, rect2Height);
36+
bool isIntersectsWith = rect1.IntersectsWith(rect2);
37+
3738
Assert.IsTrue(isIntersectsWith == shouldIntersectsWith);
3839
}
3940
}

0 commit comments

Comments
 (0)