2011-01-05 7 views
0

Ich versuche, Benutzereingabe in WPF mit Entlib 5.0 zu überprüfen. Ich möchte überprüfen, ob der Wert in der Textbox eine Zahl ist.WPF-Validierung mit Entlib 5.0 auf nicht Texteigenschaften

Mein Modell:

public class Customer 
{ 
    [Required(ErrorMessage = "Country is required")] 
    public double Country { get; set; } 
} 

XAML:

<TextBox> 
    <TextBox.Text> 
     <Binding Path="Country" UpdateSourceTrigger="PropertyChanged" > 
       <Binding.ValidationRules> 
        <vab:ValidatorRule ValidationSpecificationSource="All" SourceType="{x:Type bl:Customer}" SourcePropertyName="Country"/> 
       </Binding.ValidationRules> 
     </Binding> 
    </TextBox.Text> 
</TextBox> 

Wenn ich den Text bin Einstellung texbox Validation.HasError auf false gesetzt ist.

Irgendwelche Ideen, wie ich diese Situation bestätigen kann.

+0

Schnell Abhilfe für mich ist Wert als String-Eigenschaft zu belichten und Zeichenfolge analysieren, aber es ist nicht ideal. – baalazamon

Antwort

0

Ich habe die Lösung gefunden.

sollte Bindung sieht wie folgt aus:

<Binding Path="Country" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True" ValidatesOnExceptions="True"> 
    <Binding.ValidationRules> 
     <vab:ValidatorRule ValidationSpecificationSource="All" SourceType="{x:Type bl:Customer}" SourcePropertyName="Country"/> 
    </Binding.ValidationRules> 
</Binding> 
Verwandte Themen