Skip to content

Commit 09b627f

Browse files
committed
Add ValidationTextBox control
1 parent f8ddb3d commit 09b627f

File tree

7 files changed

+134
-22
lines changed

7 files changed

+134
-22
lines changed

samples/MvvmSampleUwp/App.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
1212
<ResourceDictionary Source="Controls/InteractiveSample.xaml" />
1313
<ResourceDictionary Source="Controls/DocumentationBlock.xaml" />
14+
<ResourceDictionary Source="Controls/ValidationTextBox.xaml" />
1415
</ResourceDictionary.MergedDictionaries>
1516

1617
<!-- Misc resources -->

samples/MvvmSampleUwp/Controls/DocumentationBlock.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
44
xmlns:local="using:MvvmSampleUwp.Controls">
55

6-
<!-- Operator button -->
76
<Style TargetType="local:DocumentationBlock">
87
<Setter Property="HorizontalAlignment" Value="Stretch" />
98
<Setter Property="HorizontalContentAlignment" Value="Stretch" />

samples/MvvmSampleUwp/Controls/InteractiveSample.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
xmlns:local="using:MvvmSampleUwp.Controls"
66
xmlns:muxc="using:Microsoft.UI.Xaml.Controls">
77

8-
<!-- Operator button -->
98
<Style TargetType="local:InteractiveSample">
109
<Setter Property="HorizontalAlignment" Value="Stretch" />
1110
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Windows.UI.Xaml;
6+
using Windows.UI.Xaml.Controls;
7+
using Windows.UI.Xaml.Input;
8+
9+
namespace MvvmSampleUwp.Controls;
10+
11+
/// <summary>
12+
/// A simple control that acts as a container for a documentation block.
13+
/// </summary>
14+
public sealed class ValidationTextBox : ContentControl
15+
{
16+
/// <summary>
17+
/// Gets or sets the <see cref="string"/> representing the text to display.
18+
/// </summary>
19+
public string Text
20+
{
21+
get => (string)GetValue(TextProperty);
22+
set => SetValue(TextProperty, value);
23+
}
24+
25+
/// <summary>
26+
/// The <see cref="DependencyProperty"/> backing <see cref="Text"/>.
27+
/// </summary>
28+
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
29+
nameof(Text),
30+
typeof(string),
31+
typeof(ValidationTextBox),
32+
new PropertyMetadata(default(string)));
33+
34+
/// <summary>
35+
/// Gets or sets the <see cref="string"/> representing the header text to display.
36+
/// </summary>
37+
public string HeaderText
38+
{
39+
get => (string)GetValue(HeaderTextProperty);
40+
set => SetValue(HeaderTextProperty, value);
41+
}
42+
43+
/// <summary>
44+
/// The <see cref="DependencyProperty"/> backing <see cref="HeaderText"/>.
45+
/// </summary>
46+
public static readonly DependencyProperty HeaderTextProperty = DependencyProperty.Register(
47+
nameof(HeaderText),
48+
typeof(string),
49+
typeof(ValidationTextBox),
50+
new PropertyMetadata(default(string)));
51+
52+
/// <summary>
53+
/// Gets or sets the <see cref="string"/> representing the placeholder text to display.
54+
/// </summary>
55+
public string PlaceholderText
56+
{
57+
get => (string)GetValue(PlaceholderTextProperty);
58+
set => SetValue(PlaceholderTextProperty, value);
59+
}
60+
61+
/// <summary>
62+
/// The <see cref="DependencyProperty"/> backing <see cref="PlaceholderText"/>.
63+
/// </summary>
64+
public static readonly DependencyProperty PlaceholderTextProperty = DependencyProperty.Register(
65+
nameof(PlaceholderText),
66+
typeof(string),
67+
typeof(ValidationTextBox),
68+
new PropertyMetadata(default(string)));
69+
70+
/// <summary>
71+
/// Gets or sets the <see cref="string"/> representing the input scope to use.
72+
/// </summary>
73+
public InputScope InputScope
74+
{
75+
get => (InputScope)GetValue(InputScopeProperty);
76+
set => SetValue(InputScopeProperty, value);
77+
}
78+
79+
/// <summary>
80+
/// The <see cref="DependencyProperty"/> backing <see cref="InputScope"/>.
81+
/// </summary>
82+
public static readonly DependencyProperty InputScopeProperty = DependencyProperty.Register(
83+
nameof(InputScope),
84+
typeof(InputScope),
85+
typeof(ValidationTextBox),
86+
new PropertyMetadata(default(InputScope)));
87+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<ResourceDictionary
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
4+
xmlns:local="using:MvvmSampleUwp.Controls">
5+
6+
<Style TargetType="local:ValidationTextBox">
7+
<Setter Property="HorizontalAlignment" Value="Left" />
8+
<Setter Property="HorizontalContentAlignment" Value="Left" />
9+
<Setter Property="Template">
10+
<Setter.Value>
11+
<ControlTemplate TargetType="local:ValidationTextBox">
12+
<Grid>
13+
<Grid.ColumnDefinitions>
14+
<ColumnDefinition Width="560" />
15+
<ColumnDefinition Width="Auto" />
16+
</Grid.ColumnDefinitions>
17+
<TextBox
18+
HorizontalAlignment="Stretch"
19+
Header="{TemplateBinding HeaderText}"
20+
InputScope="{TemplateBinding InputScope}"
21+
IsSpellCheckEnabled="False"
22+
PlaceholderText="{TemplateBinding PlaceholderText}"
23+
Text="{TemplateBinding Text}" />
24+
</Grid>
25+
</ControlTemplate>
26+
</Setter.Value>
27+
</Setter>
28+
</Style>
29+
30+
</ResourceDictionary>

samples/MvvmSampleUwp/MvvmSampleUwp.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
<Compile Include="App.xaml.cs">
120120
<DependentUpon>App.xaml</DependentUpon>
121121
</Compile>
122+
<Compile Include="Controls\ValidationTextBox.cs">
123+
<DependentUpon>ValidationTextBox.xaml</DependentUpon>
124+
</Compile>
122125
<Compile Include="Controls\DocumentationBlock.cs">
123126
<DependentUpon>DocumentationBlock.xaml</DependentUpon>
124127
</Compile>
@@ -275,6 +278,10 @@
275278
</PackageReference>
276279
</ItemGroup>
277280
<ItemGroup>
281+
<Page Include="Controls\ValidationTextBox.xaml">
282+
<Generator>MSBuild:Compile</Generator>
283+
<SubType>Designer</SubType>
284+
</Page>
278285
<Page Include="Controls\DocumentationBlock.xaml">
279286
<Generator>MSBuild:Compile</Generator>
280287
<SubType>Designer</SubType>

samples/MvvmSampleUwp/Views/ObservableValidatorPage.xaml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
x:Class="MvvmSampleUwp.Views.ObservableValidatorPage"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="using:MvvmSampleUwp.Controls"
56
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
67
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
78
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
@@ -12,36 +13,24 @@
1213

1314
<ScrollViewer Padding="{StaticResource DocumentationPageContentPadding}" CanContentRenderOutsideBounds="True">
1415
<StackPanel Spacing="16">
15-
<TextBox
16-
Width="560"
17-
HorizontalAlignment="Left"
18-
Header="Enter your first:"
16+
<controls:ValidationTextBox
17+
HeaderText="Enter your first:"
1918
InputScope="NameOrPhoneNumber"
20-
IsSpellCheckEnabled="False"
2119
PlaceholderText="First name"
2220
Text="{x:Bind ViewModel.Form.FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
23-
<TextBox
24-
Width="560"
25-
HorizontalAlignment="Left"
26-
Header="Enter your last name:"
21+
<controls:ValidationTextBox
22+
HeaderText="Enter your last name:"
2723
InputScope="NameOrPhoneNumber"
28-
IsSpellCheckEnabled="False"
2924
PlaceholderText="Last name"
3025
Text="{x:Bind ViewModel.Form.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
31-
<TextBox
32-
Width="560"
33-
HorizontalAlignment="Left"
34-
Header="Enter your email address:"
26+
<controls:ValidationTextBox
27+
HeaderText="Enter your email address:"
3528
InputScope="EmailNameOrAddress"
36-
IsSpellCheckEnabled="False"
3729
PlaceholderText="Email"
3830
Text="{x:Bind ViewModel.Form.Email, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
39-
<TextBox
40-
Width="560"
41-
HorizontalAlignment="Left"
42-
Header="Enter your phone number:"
31+
<controls:ValidationTextBox
32+
HeaderText="Enter your phone number:"
4333
InputScope="NameOrPhoneNumber"
44-
IsSpellCheckEnabled="False"
4534
PlaceholderText="Phone number"
4635
Text="{x:Bind ViewModel.Form.PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
4736

0 commit comments

Comments
 (0)