Skip to content

Commit 47e4276

Browse files
committed
Add docs paragraphs for ObservableValidator
1 parent 6a0c71c commit 47e4276

File tree

4 files changed

+159
-5
lines changed

4 files changed

+159
-5
lines changed

samples/MvvmSampleUwp/Controls/ValidationTextBox.xaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
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">
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:local="using:MvvmSampleUwp.Controls">
52

63
<Style TargetType="local:ValidationTextBox">
74
<Setter Property="HorizontalAlignment" Value="Left" />

samples/MvvmSampleUwp/MvvmSampleUwp.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@
391391
<Link>Assets\docs\ObservableObject.md</Link>
392392
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
393393
</Content>
394+
<Content Include="..\..\docs\mvvm\ObservableValidator.md">
395+
<Link>Assets\docs\ObservableValidator.md</Link>
396+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
397+
</Content>
394398
<Content Include="..\..\docs\mvvm\ObservableRecipient.md">
395399
<Link>Assets\docs\ObservableRecipient.md</Link>
396400
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

samples/MvvmSampleUwp/Views/ObservableValidatorPage.xaml

Lines changed: 151 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,163 @@
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"
6+
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
57
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
69
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
710
xmlns:widgets="using:MvvmSampleUwp.Views.Widgets"
811
NavigationCacheMode="Enabled"
912
mc:Ignorable="d">
13+
<interactivity:Interaction.Behaviors>
14+
<core:EventTriggerBehavior EventName="Loaded">
15+
<core:InvokeCommandAction Command="{x:Bind ViewModel.LoadDocsCommand}" CommandParameter="ObservableValidator" />
16+
</core:EventTriggerBehavior>
17+
</interactivity:Interaction.Behaviors>
1018

1119
<ScrollViewer Padding="{StaticResource DocumentationPageContentPadding}" CanContentRenderOutsideBounds="True">
12-
<widgets:ValidationFormWidget DataContext="{x:Bind ViewModel.Form}" />
20+
<StackPanel Spacing="16">
21+
<controls:DocumentationBlock Text="{x:Bind ViewModel.GetParagraph('ObservableValidator'), Mode=OneWay}" />
22+
<controls:DocumentationBlock Text="{x:Bind ViewModel.GetParagraph('How it works'), Mode=OneWay}" />
23+
<controls:DocumentationBlock Text="{x:Bind ViewModel.GetParagraph('Simple property'), Mode=OneWay}" />
24+
<controls:InteractiveSample xml:space="preserve">
25+
<controls:InteractiveSample.Content>
26+
<widgets:ValidationFormWidget DataContext="{x:Bind ViewModel.Form}" />
27+
</controls:InteractiveSample.Content>
28+
<controls:InteractiveSample.XamlCode>
29+
&lt;StackPanel Spacing=&quot;16&quot;&gt;
30+
31+
&lt;!-- Text forms --&gt;
32+
&lt;controls:ValidationTextBox
33+
HeaderText=&quot;Enter your first:&quot;
34+
PlaceholderText=&quot;First name&quot;
35+
PropertyName=&quot;FirstName&quot;
36+
Text=&quot;{x:Bind ViewModel.FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}&quot; /&gt;
37+
&lt;controls:ValidationTextBox
38+
HeaderText=&quot;Enter your last name:&quot;
39+
PlaceholderText=&quot;Last name&quot;
40+
PropertyName=&quot;LastName&quot;
41+
Text=&quot;{x:Bind ViewModel.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}&quot; /&gt;
42+
&lt;controls:ValidationTextBox
43+
HeaderText=&quot;Enter your email address:&quot;
44+
PlaceholderText=&quot;Email&quot;
45+
PropertyName=&quot;Email&quot;
46+
Text=&quot;{x:Bind ViewModel.Email, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}&quot; /&gt;
47+
&lt;controls:ValidationTextBox
48+
HeaderText=&quot;Enter your phone number:&quot;
49+
PlaceholderText=&quot;Phone number&quot;
50+
PropertyName=&quot;PhoneNumber&quot;
51+
Text=&quot;{x:Bind ViewModel.PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}&quot; /&gt;
52+
53+
&lt;!-- Submit command --&gt;
54+
&lt;Button Command=&quot;{x:Bind ViewModel.SubmitCommand}&quot; Content=&quot;Submit&quot; /&gt;
55+
56+
&lt;!-- Popups --&gt;
57+
&lt;Grid&gt;
58+
&lt;muxc:InfoBar
59+
x:Name=&quot;SuccessInfoBar&quot;
60+
Title=&quot;Success&quot;
61+
Message=&quot;The form was filled in correctly.&quot;
62+
Severity=&quot;Success&quot;&gt;
63+
&lt;interactivity:Interaction.Behaviors&gt;
64+
&lt;interactions:EventTriggerBehavior EventName=&quot;FormSubmissionCompleted&quot; SourceObject=&quot;{x:Bind ViewModel}&quot;&gt;
65+
&lt;interactions:ChangePropertyAction
66+
PropertyName=&quot;IsOpen&quot;
67+
TargetObject=&quot;{x:Bind SuccessInfoBar}&quot;
68+
Value=&quot;True&quot; /&gt;
69+
&lt;interactions:ChangePropertyAction
70+
PropertyName=&quot;IsOpen&quot;
71+
TargetObject=&quot;{x:Bind FailureInfoBar}&quot;
72+
Value=&quot;False&quot; /&gt;
73+
&lt;/interactions:EventTriggerBehavior&gt;
74+
&lt;/interactivity:Interaction.Behaviors&gt;
75+
&lt;/muxc:InfoBar&gt;
76+
&lt;muxc:InfoBar
77+
x:Name=&quot;FailureInfoBar&quot;
78+
Title=&quot;Error&quot;
79+
Message=&quot;The form was filled in with some errors.&quot;
80+
Severity=&quot;Error&quot;&gt;
81+
&lt;muxc:InfoBar.ActionButton&gt;
82+
&lt;Button Command=&quot;{x:Bind ViewModel.ShowErrorsCommand}&quot; Content=&quot;Show errors&quot; /&gt;
83+
&lt;/muxc:InfoBar.ActionButton&gt;
84+
&lt;interactivity:Interaction.Behaviors&gt;
85+
&lt;interactions:EventTriggerBehavior EventName=&quot;FormSubmissionFailed&quot; SourceObject=&quot;{x:Bind ViewModel}&quot;&gt;
86+
&lt;interactions:ChangePropertyAction
87+
PropertyName=&quot;IsOpen&quot;
88+
TargetObject=&quot;{x:Bind SuccessInfoBar}&quot;
89+
Value=&quot;False&quot; /&gt;
90+
&lt;interactions:ChangePropertyAction
91+
PropertyName=&quot;IsOpen&quot;
92+
TargetObject=&quot;{x:Bind FailureInfoBar}&quot;
93+
Value=&quot;True&quot; /&gt;
94+
&lt;/interactions:EventTriggerBehavior&gt;
95+
&lt;/interactivity:Interaction.Behaviors&gt;
96+
&lt;/muxc:InfoBar&gt;
97+
&lt;/Grid&gt;
98+
&lt;/StackPanel&gt;
99+
</controls:InteractiveSample.XamlCode>
100+
<controls:InteractiveSample.CSharpCode>
101+
public partial class ObservableForm : ObservableValidator
102+
{
103+
private readonly IDialogService DialogService;
104+
105+
public ObservableForm(IDialogService dialogService)
106+
{
107+
DialogService = dialogService;
108+
}
109+
110+
public event EventHandler? FormSubmissionCompleted;
111+
public event EventHandler? FormSubmissionFailed;
112+
113+
[ObservableProperty]
114+
[Required]
115+
[MinLength(2)]
116+
[MaxLength(100)]
117+
private string? firstName;
118+
119+
[ObservableProperty]
120+
[Required]
121+
[MinLength(2)]
122+
[MaxLength(100)]
123+
private string? lastName;
124+
125+
[ObservableProperty]
126+
[Required]
127+
[EmailAddress]
128+
private string? email;
129+
130+
[ObservableProperty]
131+
[Required]
132+
[Phone]
133+
private string? phoneNumber;
134+
135+
[ICommand]
136+
private void Submit()
137+
{
138+
ValidateAllProperties();
139+
140+
if (HasErrors)
141+
{
142+
FormSubmissionFailed?.Invoke(this, EventArgs.Empty);
143+
}
144+
else
145+
{
146+
FormSubmissionCompleted?.Invoke(this, EventArgs.Empty);
147+
}
148+
}
149+
150+
[ICommand]
151+
private void ShowErrors()
152+
{
153+
string message = string.Join(Environment.NewLine, GetErrors().Select(e =&gt; e.ErrorMessage));
154+
155+
_ = DialogService.ShowMessageDialogAsync(&quot;Validation errors&quot;, message);
156+
}
157+
}
158+
</controls:InteractiveSample.CSharpCode>
159+
</controls:InteractiveSample>
160+
<controls:DocumentationBlock Text="{x:Bind ViewModel.GetParagraph('Custom validation methods'), Mode=OneWay}" />
161+
<controls:DocumentationBlock Text="{x:Bind ViewModel.GetParagraph('Custom validation attributes'), Mode=OneWay}" />
162+
</StackPanel>
13163
</ScrollViewer>
14164
</Page>

samples/MvvmSampleUwp/Views/Widgets/ValidationFormWidget.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
mc:Ignorable="d">
1414

1515
<StackPanel Spacing="16">
16+
17+
<!-- Text forms -->
1618
<controls:ValidationTextBox
1719
HeaderText="Enter your first:"
1820
PlaceholderText="First name"
@@ -34,6 +36,7 @@
3436
PropertyName="PhoneNumber"
3537
Text="{x:Bind ViewModel.PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
3638

39+
<!-- Submit button -->
3740
<Button Command="{x:Bind ViewModel.SubmitCommand}" Content="Submit" />
3841

3942
<!-- Popups -->

0 commit comments

Comments
 (0)