Ich habe ein Problem mit dem PropertyComparisonValidator von EntLib 5.0. Ich habe ein einfaches Formular mit einem Min- und einem Max-Feld eingerichtet. Die Validierung lautet: Wenn Min> = Max, sind beide Eigenschaften ungültig.WPF, EntLib: PropertyComparisonValidator aktualisiert die Benutzeroberfläche des verglichenen Werts nicht
[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); }
}
Die 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}"/>
Das Problem ist die Benutzeroberfläche. Wenn ich Min = 5 und Max = 4 eingeben, sind beide ungültig und mit einem roten Rand markiert.
ABER wenn ich Update Min = 3 -> beide korrekt sein. Überprüfung der Validierung, es gibt keinen Fehler und ist perfekt. -> Aber die Benutzeroberfläche bleibt immer noch rot für Max. Nur Min wird aktualisiert, da dieses Feld eine PropertyChanged hatte.
Gibt es ein funktionierendes Min Max-Beispiel mit EntLib für WPF?
Vielen Dank. Michele