Skip to content

Commit 6a0c71c

Browse files
committed
Move validation form to ValidationFormWidget control
1 parent 8203709 commit 6a0c71c

File tree

4 files changed

+110
-75
lines changed

4 files changed

+110
-75
lines changed

samples/MvvmSampleUwp/MvvmSampleUwp.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@
188188
<Compile Include="Views\Widgets\SubredditWidget.xaml.cs">
189189
<DependentUpon>SubredditWidget.xaml</DependentUpon>
190190
</Compile>
191+
<Compile Include="Views\Widgets\ValidationFormWidget.xaml.cs">
192+
<DependentUpon>ValidationFormWidget.xaml</DependentUpon>
193+
</Compile>
191194
</ItemGroup>
192195
<ItemGroup>
193196
<AppxManifest Include="Package.appxmanifest">
@@ -362,6 +365,10 @@
362365
<SubType>Designer</SubType>
363366
<Generator>MSBuild:Compile</Generator>
364367
</Page>
368+
<Page Include="Views\Widgets\ValidationFormWidget.xaml">
369+
<SubType>Designer</SubType>
370+
<Generator>MSBuild:Compile</Generator>
371+
</Page>
365372
</ItemGroup>
366373
<ItemGroup>
367374
<Content Include="..\..\docs\mvvm\AsyncRelayCommand.md">

samples/MvvmSampleUwp/Views/ObservableValidatorPage.xaml

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,86 +2,13 @@
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"
65
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7-
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
8-
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
96
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10-
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
7+
xmlns:widgets="using:MvvmSampleUwp.Views.Widgets"
118
NavigationCacheMode="Enabled"
129
mc:Ignorable="d">
1310

1411
<ScrollViewer Padding="{StaticResource DocumentationPageContentPadding}" CanContentRenderOutsideBounds="True">
15-
<StackPanel Spacing="16">
16-
<controls:ValidationTextBox
17-
DataContext="{x:Bind ViewModel.Form}"
18-
HeaderText="Enter your first:"
19-
PlaceholderText="First name"
20-
PropertyName="FirstName"
21-
Text="{x:Bind ViewModel.Form.FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
22-
<controls:ValidationTextBox
23-
DataContext="{x:Bind ViewModel.Form}"
24-
HeaderText="Enter your last name:"
25-
PlaceholderText="Last name"
26-
PropertyName="LastName"
27-
Text="{x:Bind ViewModel.Form.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
28-
<controls:ValidationTextBox
29-
DataContext="{x:Bind ViewModel.Form}"
30-
HeaderText="Enter your email address:"
31-
PlaceholderText="Email"
32-
PropertyName="Email"
33-
Text="{x:Bind ViewModel.Form.Email, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
34-
<controls:ValidationTextBox
35-
DataContext="{x:Bind ViewModel.Form}"
36-
HeaderText="Enter your phone number:"
37-
PlaceholderText="Phone number"
38-
PropertyName="PhoneNumber"
39-
Text="{x:Bind ViewModel.Form.PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
40-
41-
<Button Command="{x:Bind ViewModel.Form.SubmitCommand}" Content="Submit" />
42-
43-
<!-- Popups -->
44-
<Grid>
45-
<muxc:InfoBar
46-
x:Name="SuccessInfoBar"
47-
Title="Success"
48-
Message="The form was filled in correctly."
49-
Severity="Success">
50-
<interactivity:Interaction.Behaviors>
51-
<interactions:EventTriggerBehavior EventName="FormSubmissionCompleted" SourceObject="{x:Bind ViewModel.Form}">
52-
<interactions:ChangePropertyAction
53-
PropertyName="IsOpen"
54-
TargetObject="{x:Bind SuccessInfoBar}"
55-
Value="True" />
56-
<interactions:ChangePropertyAction
57-
PropertyName="IsOpen"
58-
TargetObject="{x:Bind FailureInfoBar}"
59-
Value="False" />
60-
</interactions:EventTriggerBehavior>
61-
</interactivity:Interaction.Behaviors>
62-
</muxc:InfoBar>
63-
<muxc:InfoBar
64-
x:Name="FailureInfoBar"
65-
Title="Error"
66-
Message="The form was filled in with some errors."
67-
Severity="Error">
68-
<muxc:InfoBar.ActionButton>
69-
<Button Command="{x:Bind ViewModel.Form.ShowErrorsCommand}" Content="Show errors" />
70-
</muxc:InfoBar.ActionButton>
71-
<interactivity:Interaction.Behaviors>
72-
<interactions:EventTriggerBehavior EventName="FormSubmissionFailed" SourceObject="{x:Bind ViewModel.Form}">
73-
<interactions:ChangePropertyAction
74-
PropertyName="IsOpen"
75-
TargetObject="{x:Bind SuccessInfoBar}"
76-
Value="False" />
77-
<interactions:ChangePropertyAction
78-
PropertyName="IsOpen"
79-
TargetObject="{x:Bind FailureInfoBar}"
80-
Value="True" />
81-
</interactions:EventTriggerBehavior>
82-
</interactivity:Interaction.Behaviors>
83-
</muxc:InfoBar>
84-
</Grid>
85-
</StackPanel>
12+
<widgets:ValidationFormWidget DataContext="{x:Bind ViewModel.Form}" />
8613
</ScrollViewer>
8714
</Page>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<UserControl
2+
x:Class="MvvmSampleUwp.Views.Widgets.ValidationFormWidget"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="using:MvvmSampleUwp.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
8+
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
9+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
11+
d:DesignHeight="300"
12+
d:DesignWidth="400"
13+
mc:Ignorable="d">
14+
15+
<StackPanel Spacing="16">
16+
<controls:ValidationTextBox
17+
HeaderText="Enter your first:"
18+
PlaceholderText="First name"
19+
PropertyName="FirstName"
20+
Text="{x:Bind ViewModel.FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
21+
<controls:ValidationTextBox
22+
HeaderText="Enter your last name:"
23+
PlaceholderText="Last name"
24+
PropertyName="LastName"
25+
Text="{x:Bind ViewModel.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
26+
<controls:ValidationTextBox
27+
HeaderText="Enter your email address:"
28+
PlaceholderText="Email"
29+
PropertyName="Email"
30+
Text="{x:Bind ViewModel.Email, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
31+
<controls:ValidationTextBox
32+
HeaderText="Enter your phone number:"
33+
PlaceholderText="Phone number"
34+
PropertyName="PhoneNumber"
35+
Text="{x:Bind ViewModel.PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
36+
37+
<Button Command="{x:Bind ViewModel.SubmitCommand}" Content="Submit" />
38+
39+
<!-- Popups -->
40+
<Grid>
41+
<muxc:InfoBar
42+
x:Name="SuccessInfoBar"
43+
Title="Success"
44+
Message="The form was filled in correctly."
45+
Severity="Success">
46+
<interactivity:Interaction.Behaviors>
47+
<interactions:EventTriggerBehavior EventName="FormSubmissionCompleted" SourceObject="{x:Bind ViewModel}">
48+
<interactions:ChangePropertyAction
49+
PropertyName="IsOpen"
50+
TargetObject="{x:Bind SuccessInfoBar}"
51+
Value="True" />
52+
<interactions:ChangePropertyAction
53+
PropertyName="IsOpen"
54+
TargetObject="{x:Bind FailureInfoBar}"
55+
Value="False" />
56+
</interactions:EventTriggerBehavior>
57+
</interactivity:Interaction.Behaviors>
58+
</muxc:InfoBar>
59+
<muxc:InfoBar
60+
x:Name="FailureInfoBar"
61+
Title="Error"
62+
Message="The form was filled in with some errors."
63+
Severity="Error">
64+
<muxc:InfoBar.ActionButton>
65+
<Button Command="{x:Bind ViewModel.ShowErrorsCommand}" Content="Show errors" />
66+
</muxc:InfoBar.ActionButton>
67+
<interactivity:Interaction.Behaviors>
68+
<interactions:EventTriggerBehavior EventName="FormSubmissionFailed" SourceObject="{x:Bind ViewModel}">
69+
<interactions:ChangePropertyAction
70+
PropertyName="IsOpen"
71+
TargetObject="{x:Bind SuccessInfoBar}"
72+
Value="False" />
73+
<interactions:ChangePropertyAction
74+
PropertyName="IsOpen"
75+
TargetObject="{x:Bind FailureInfoBar}"
76+
Value="True" />
77+
</interactions:EventTriggerBehavior>
78+
</interactivity:Interaction.Behaviors>
79+
</muxc:InfoBar>
80+
</Grid>
81+
</StackPanel>
82+
</UserControl>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 MvvmSample.Core.ViewModels;
6+
using Windows.UI.Xaml.Controls;
7+
8+
namespace MvvmSampleUwp.Views.Widgets
9+
{
10+
public sealed partial class ValidationFormWidget : UserControl
11+
{
12+
public ValidationFormWidget()
13+
{
14+
this.InitializeComponent();
15+
}
16+
17+
public ObservableValidatorPageViewModel.ObservableForm ViewModel => (ObservableValidatorPageViewModel.ObservableForm)DataContext;
18+
}
19+
}

0 commit comments

Comments
 (0)