|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
Classe Validation
Namespace: System.Windows.Controls
Assembly: PresentationFramework (em PresentationFramework.dll)
O tipo Validation expõe os membros a seguir.
| Nome | Descrição | |
|---|---|---|
![]() | Errors | |
![]() | ErrorTemplate | |
![]() | HasError | |
![]() | ValidationAdornerSite | |
![]() | ValidationAdornerSiteFor |
| Nome | Descrição | |
|---|---|---|
![]() ![]() | AddErrorHandler | |
![]() ![]() | ClearInvalid | |
![]() ![]() | GetErrors | |
![]() ![]() | GetErrorTemplate | |
![]() ![]() | GetHasError | |
![]() ![]() | GetValidationAdornerSite | |
![]() ![]() | GetValidationAdornerSiteFor | |
![]() ![]() | MarkInvalid | |
![]() ![]() | RemoveErrorHandler | |
![]() ![]() | SetErrorTemplate | |
![]() ![]() | SetValidationAdornerSite | |
![]() ![]() | SetValidationAdornerSiteFor |
| Nome | Descrição | |
|---|---|---|
![]() | Error |
| Nome | Descrição | |
|---|---|---|
![]() ![]() | ErrorEvent | |
![]() ![]() | ErrorsProperty | |
![]() ![]() | ErrorTemplateProperty | |
![]() ![]() | HasErrorProperty | |
![]() ![]() | ValidationAdornerSiteForProperty | |
![]() ![]() | ValidationAdornerSiteProperty |
<TextBox Name="textBox1" Width="50" FontSize="15" Validation.ErrorTemplate="{StaticResource validationTemplate}" Style="{StaticResource textBoxInError}" Grid.Row="1" Grid.Column="1" Margin="2"> <TextBox.Text> <Binding Path="Age" Source="{StaticResource ods}" UpdateSourceTrigger="PropertyChanged" > <Binding.ValidationRules> <c:AgeRangeRule Min="21" Max="130"/> </Binding.ValidationRules> </Binding> </TextBox.Text> </TextBox>
public class AgeRangeRule : ValidationRule { private int _min; private int _max; public AgeRangeRule() { } public int Min { get { return _min; } set { _min = value; } } public int Max { get { return _max; } set { _max = value; } } public override ValidationResult Validate(object value, CultureInfo cultureInfo) { int age = 0; try { if (((string)value).Length > 0) age = Int32.Parse((String)value); } catch (Exception e) { return new ValidationResult(false, "Illegal characters or " + e.Message); } if ((age < Min) || (age > Max)) { return new ValidationResult(false, "Please enter an age in the range: " + Min + " - " + Max + "."); } else { return new ValidationResult(true, null); } } }
<ControlTemplate x:Key="validationTemplate"> <DockPanel> <TextBlock Foreground="Red" FontSize="20">!</TextBlock> <AdornedElementPlaceholder/> </DockPanel> </ControlTemplate>
<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/> </Trigger> </Style.Triggers> </Style>
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Função Server Core sem suporte), Windows Server 2008 R2 (Função Server Core com suporte com o SP1 ou posterior, Itanium sem suporte)
O .NET Framework não oferece suporte a todas as versões de cada plataforma. Para obter uma lista das versões com suporte, consulte .Requisitos de sistema do NET Framework.
