0
我正在使用WPF,並且我有一個實體綁定到一系列控件。實體與兩個一流水平驗證飾如下:雙NHibernate類級別驗證器問題
[ExampleValidator1, ExampleValidator2]
public class Entity
一個實體的一系列領域,其中並非全部始終顯示,依賴於從組合框中選擇的。 驗證器適用於這些選擇的,如果實體的「類型」不匹配,驗證返回true特定的驗證,顯然正確的驗證將驗證實際的字段如下:
public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
{
constraintValidatorContext.DisableDefaultError();
var allPropertiesValid = true;
var entity= (Entity)value;
if (supplier.ParticularEntityType)
{
return true;
}
if (String.IsNullOrEmpty(entity.Name) || entity.Name.Length > 50)
{
constraintValidatorContext.AddInvalid<Entity, string>("must be 50 or shorter and not empty", x => x.Name);
allPropertiesValid = false;
}
和XAML如下:
<TextBox Grid.Row="0" Grid.Column="3">
<TextBox.Text>
<Binding Path="Entity.Name" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True">
</Binding>
</TextBox.Text>
</TextBox>
顯然我得到漂亮的紅色框和工具提示,通知用戶驗證要求。
我的問題是,當組合框中的選擇更改時,紅色突出顯示仍然存在(當隱藏控件時會變成一個小紅色方框)。 請有人指示我請正確的方式!