空のときにテキストボックスの枠線を赤くしたい。ここに私のXAMLのです:WPF TextBoxで赤い枠線の設定が有効になった
<TextBox Style="{StaticResource TextBoxEmptyError}" Name="tbFilename" Grid.Column="1" >
<Binding Path="Text" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
<Binding.ValidationRules>
<local:EmptyRule />
</Binding.ValidationRules>
</Binding>
</TextBox>
私は設定しようとしているスタイル:
<Style x:Key="TextBoxEmptyError" TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="BorderThickness" Value="2" />
<Setter Property="BorderBrush" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
EmptyRule:検証方法が全く使用されないように、デバッガで
public class EmptyRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (string.IsNullOrEmpty(value as string))
return new ValidationResult(false, null);
else
return new ValidationResult(true, null);
}
}
それが見えます。 私は何が間違っていますか?
はどんな質問をすること自由に感じ:
その後、XAMLは、このようになります必要があります。私の返事があなたに役立つと感じたら、私の返事を答えとしてマークして、将来の他の人の検索を簡単にすることができます。 http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-workをご覧ください。 – StepUp