2011-01-05 10 views
0

Entlib 5.0でWPFでのユーザー入力を検証しようとしています。テキストボックスの値が数値かどうかをチェックしたいEntlib 5.0での非テキストプロパティのWPF検証

マイモデル:

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> 

私はValidation.HasErrorがfalseに設定されているtexboxするテキストを設定しています。

どのように私はこの状況を検証することができますどのようなアイデア。

+0

クイック回避策は、文字列プロパティとして値を公開して文字列を解析することであるが、それは理想的ではありません。 – baalazamon

答えて

0

私は解決策を見つけました。

はすべき結合すると、次のようになります。私のために

<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> 
関連する問題