Improve Stylet.Samples.Validation, and remove .TryClose

This commit is contained in:
Antony Male 2015-03-14 14:53:55 +00:00
parent 56395d8a8a
commit a5f642d95c
6 changed files with 15 additions and 11 deletions

View File

@ -13,7 +13,7 @@ namespace Stylet.Samples.HelloDialog
public void Close() public void Close()
{ {
this.TryClose(true); this.RequestClose(true);
} }
} }
} }

View File

@ -21,7 +21,7 @@
<DockPanel LastChildFill="False"> <DockPanel LastChildFill="False">
<TextBlock DockPanel.Dock="Bottom" HorizontalAlignment="Left" Width="{Binding ElementName=CustomAdorner, Path=ActualWidth}" <TextBlock DockPanel.Dock="Bottom" HorizontalAlignment="Left" Width="{Binding ElementName=CustomAdorner, Path=ActualWidth}"
Foreground="OrangeRed" TextTrimming="WordEllipsis" Foreground="OrangeRed" TextTrimming="WordEllipsis"
Text="{Binding ElementName=CustomAdorner,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"/> Text="{Binding ElementName=CustomAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"/>
<Border Background="OrangeRed" DockPanel.Dock="Right" Margin="5,0,0,0" VerticalAlignment="Top" <Border Background="OrangeRed" DockPanel.Dock="Right" Margin="5,0,0,0" VerticalAlignment="Top"
Width="20" Height="20" CornerRadius="5"> Width="20" Height="20" CornerRadius="5">
<TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" FontWeight="Bold" Foreground="white" /> <TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" FontWeight="Bold" Foreground="white" />
@ -53,19 +53,19 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Target="{Binding ElementName=UserName}">UserName:</Label> <Label Grid.Row="0" Grid.Column="0" Target="{Binding ElementName=UserName}">UserName:</Label>
<TextBox Grid.Row="0" Grid.Column="1" x:Name="UserName" Text="{Binding UserName}"/> <TextBox Grid.Row="0" Grid.Column="1" x:Name="UserName" Text="{Binding UserName, UpdateSourceTrigger=PropertyChanged}"/>
<Label Grid.Row="1" Grid.Column="0" Target="{Binding ElementName=Email}">Email:</Label> <Label Grid.Row="1" Grid.Column="0" Target="{Binding ElementName=Email}">Email:</Label>
<TextBox Grid.Row="1" Grid.Column="1" x:Name="Email" Text="{Binding Email}"/> <TextBox Grid.Row="1" Grid.Column="1" x:Name="Email" Text="{Binding Email, UpdateSourceTrigger=PropertyChanged}"/>
<Label Grid.Row="2" Grid.Column="0" Target="{Binding ElementName=Age}">Age:</Label> <Label Grid.Row="2" Grid.Column="0" Target="{Binding ElementName=Age}">Age:</Label>
<TextBox Grid.Row="2" Grid.Column="1" x:Name="Age" Text="{Binding Age}"/> <TextBox Grid.Row="2" Grid.Column="1" x:Name="Age" Text="{Binding Age, UpdateSourceTrigger=PropertyChanged}"/>
<Label Grid.Row="3" Grid.Column="0" Target="{Binding ElementName=Password}">Password:</Label> <Label Grid.Row="3" Grid.Column="0" Target="{Binding ElementName=Password}">Password:</Label>
<PasswordBox Grid.Row="3" Grid.Column="1" x:Name="Password" xaml:Secure.Password="{Binding Password}"/> <PasswordBox Grid.Row="3" Grid.Column="1" x:Name="Password" xaml:Secure.Password="{Binding Password, UpdateSourceTrigger=PropertyChanged}"/>
<Label Grid.Row="4" Grid.Column="0" Target="{Binding ElementName=PasswordConfirmation}">Password Confirmation:</Label> <Label Grid.Row="4" Grid.Column="0" Target="{Binding ElementName=PasswordConfirmation}">Password Confirmation:</Label>
<PasswordBox Grid.Row="4" Grid.Column="1" x:Name="PasswordConfirmation" xaml:Secure.Password="{Binding PasswordConfirmation}"/> <PasswordBox Grid.Row="4" Grid.Column="1" x:Name="PasswordConfirmation" xaml:Secure.Password="{Binding PasswordConfirmation, UpdateSourceTrigger=PropertyChanged}"/>
<CheckBox Grid.Row="5" Grid.Column="0" IsChecked="{Binding ShouldAutoValidate}">Auto-Validate</CheckBox> <CheckBox Grid.Row="5" Grid.Column="0" IsChecked="{Binding ShouldAutoValidate}">Auto-Validate</CheckBox>
<Button Grid.Row="5" Grid.Column="1" Command="{s:Action Submit}" HorizontalAlignment="Left">Submit</Button> <Button Grid.Row="5" Grid.Column="1" Command="{s:Action Submit}" HorizontalAlignment="Left">Submit</Button>

View File

@ -27,6 +27,10 @@ namespace Stylet.Samples.ModelValidation.Pages
public UserViewModel(IWindowManager windowManager, IModelValidator<UserViewModel> validator) : base(validator) public UserViewModel(IWindowManager windowManager, IModelValidator<UserViewModel> validator) : base(validator)
{ {
this.windowManager = windowManager; this.windowManager = windowManager;
// Force initial validation
this.Validate();
// Whenever password changes, we need to re-validate PasswordConfirmation
this.Bind(x => x.Password, (o, e) => this.ValidateProperty(() => this.PasswordConfirmation));
} }
protected override void OnValidationStateChanged(IEnumerable<string> changedProperties) protected override void OnValidationStateChanged(IEnumerable<string> changedProperties)

View File

@ -23,7 +23,7 @@ namespace Stylet.Samples.RedditBrowser.Pages
public void GoBack() public void GoBack()
{ {
this.TryClose(); this.RequestClose();
} }
} }
} }

View File

@ -29,13 +29,13 @@ namespace Stylet.Samples.RedditBrowser.Pages
} }
catch (Exception) catch (Exception)
{ {
this.TryClose(); this.RequestClose();
} }
} }
public void Close() public void Close()
{ {
this.TryClose(); this.RequestClose();
} }
public bool CanNext public bool CanNext

View File

@ -42,7 +42,7 @@ namespace Stylet.Samples.RedditBrowser.Pages
// If we're setting the ActiveItem to null, that means everything's been closed - close ourselves // If we're setting the ActiveItem to null, that means everything's been closed - close ourselves
if (newItem == null) if (newItem == null)
this.TryClose(); this.RequestClose();
} }
} }