WPF,entlib:propertyComparisonValidator不会更新比较值的UI
我对Entlib 5.0的属性库存效果有问题。 我设置了一个带有分钟和最大字段的简单表格。 验证是:当min> = max时,两个属性都是无效的。
[RangeValidator(10, RangeBoundaryType.Inclusive, 100,
RangeBoundaryType.Inclusive)]
[PropertyComparisonValidator("MinVal", ComparisonOperator.GreaterThanEqual,
MessageTemplate = @"Min cannot be greater or equal to Max")]
[Required(ErrorMessage = @"MaxVal is required")]
public int MaxVal
{
get { return (int)this.GetValue(MaxValProperty); }
set { this.SetValue(MaxValProperty, value); }
}
[RangeValidator(1, RangeBoundaryType.Inclusive, 100,
RangeBoundaryType.Inclusive)]
[PropertyComparisonValidator("MaxVal", ComparisonOperator.LessThanEqual,
MessageTemplate = @"Max cannot be less or equal to Min")]
[Required(ErrorMessage = @"MinVal is required")]
public int MinVal
{
get { return (int)this.GetValue(MinValProperty); }
set { this.SetValue(MinValProperty, value); }
}
XAML:
<TextBox x:Name="txtMinVal" Margin="0,0,5,0" TextWrapping="Wrap" Text="{Binding MinVal, ValidatesOnDataErrors=true, NotifyOnValidationError=true, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" VerticalAlignment="Center" Grid.Row="1"
/>
<Label x:Name="lblMinVal" Content="Min Value" Margin="5,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Row="1"/>
<TextBox x:Name="txtMaxVal" Margin="0,0,5,0" TextWrapping="Wrap" Text="{Binding MaxVal, ValidatesOnDataErrors=true, NotifyOnValidationError=true, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" VerticalAlignment="Center" Grid.Row="2"
/>
<Label x:Name="lblMaxVal" Content="Max Value" Margin="5,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Row="2"/>
<Button x:Name="btnSave" Content="Save" Margin="0" Grid.Row="3" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center" IsEnabled="{Binding IsValid}"/>
问题是UI。 如果我输入最小= 5和max = 4,则两者都是无效的,并用红色边框标记。
但是,如果我更新最小= 3 - &gt;两者都改成正确。 检查验证它不会返回没有错误,并且是完美的。 ->但是UI仍然是最大的红色。只能更新最小的,因为该字段的属性换了。
对于WPF,是否有一个工作最小的最大示例?
谢谢。 米歇尔
I have a problem with the PropertyComparisonValidator of EntLib 5.0.
I set up an simple form with an Min and a Max field.
The validation is: when Min >= Max both properties are invalid.
[RangeValidator(10, RangeBoundaryType.Inclusive, 100,
RangeBoundaryType.Inclusive)]
[PropertyComparisonValidator("MinVal", ComparisonOperator.GreaterThanEqual,
MessageTemplate = @"Min cannot be greater or equal to Max")]
[Required(ErrorMessage = @"MaxVal is required")]
public int MaxVal
{
get { return (int)this.GetValue(MaxValProperty); }
set { this.SetValue(MaxValProperty, value); }
}
[RangeValidator(1, RangeBoundaryType.Inclusive, 100,
RangeBoundaryType.Inclusive)]
[PropertyComparisonValidator("MaxVal", ComparisonOperator.LessThanEqual,
MessageTemplate = @"Max cannot be less or equal to Min")]
[Required(ErrorMessage = @"MinVal is required")]
public int MinVal
{
get { return (int)this.GetValue(MinValProperty); }
set { this.SetValue(MinValProperty, value); }
}
The XAML:
<TextBox x:Name="txtMinVal" Margin="0,0,5,0" TextWrapping="Wrap" Text="{Binding MinVal, ValidatesOnDataErrors=true, NotifyOnValidationError=true, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" VerticalAlignment="Center" Grid.Row="1"
/>
<Label x:Name="lblMinVal" Content="Min Value" Margin="5,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Row="1"/>
<TextBox x:Name="txtMaxVal" Margin="0,0,5,0" TextWrapping="Wrap" Text="{Binding MaxVal, ValidatesOnDataErrors=true, NotifyOnValidationError=true, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" VerticalAlignment="Center" Grid.Row="2"
/>
<Label x:Name="lblMaxVal" Content="Max Value" Margin="5,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Row="2"/>
<Button x:Name="btnSave" Content="Save" Margin="0" Grid.Row="3" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center" IsEnabled="{Binding IsValid}"/>
The problem is the UI.
If I input Min=5 and Max=4 then both are invalid and marked with a red border.
BUT if I update Min=3 --> both shold be correct.
Checking the validation it returns NO ERROR and is perfect.
-> But the UI still remains red for Max. Only Min will be updated, because this field had a PropertyChanged.
Is there a working Min Max example with EntLib for WPF?
Thank you.
Michele
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,VAB 5.0 中存在一个有关
PropertyComparisonValidator
的设计缺陷。使用集成库之一时,您无法使用此验证器装饰您的对象(就像对 WPF 所做的那样)。这是不幸的,因为我认为使用PropertyComparisonValidator
比在[SelfValidation]
方法中编写它要干净得多。我在 VAB 论坛上创建了有关此问题的讨论。我希望 EntLib 团队能够在下一个版本中解决这个问题。
同时:不要使用
PropertyComparisonValidator
并将这些验证写入类型的[SelfValidation]
方法中。我希望这有帮助。
Unfortunately, there is a design flaw in VAB 5.0 concerning the
PropertyComparisonValidator
. You can't decorate your objects with this validator when using one of the integration libraries (as you do for WPF). This is unfortunate, because I think that using aPropertyComparisonValidator
is much cleaner than writing this in a[SelfValidation]
method.I created a discussion about this on the VAB forum. I hope the EntLib team will fix this in the next release.
In the meantime: don't use the
PropertyComparisonValidator
and write these validations in the[SelfValidation]
method of a type.I hope this helps.