Hallo,
ich habe zwei Textboxen min und max, die ich validieren möchte in zwei stufen.
Stufe 1:
textbox_min auf double werte überprüfen (das geht)
textbox_max auf double werte überprüfen (das geht)
Stufe2:
prüfen ob textbox_min.inhalt < textbox_max.inhalt ????
xaml:
...
<TextBox Grid.Row="0" Grid.Column="2" MaxLength="15" FontWeight="Normal" Name="sabMinTextBox" Width="60" HorizontalContentAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalContentAlignment="Center">
<TextBox.Text>
<Binding Path="SabMin" ValidatesOnDataErrors="True" ValidatesOnExceptions="True" UpdateSourceTrigger="PropertyChanged" Mode="OneWayToSource"/>
</TextBox.Text>
</TextBox>
<ContentPresenter Grid.Row="1" Grid.Column="2" Content="{Binding ElementName=sabMinTextBox, Path=(Validation.Errors).CurrentItem}"/>
<TextBox Grid.Row="0" Grid.Column="6" MaxLength="15" FontWeight="Normal" Name="sabMaxTextBox" Width="60" HorizontalContentAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalContentAlignment="Center">
<TextBox.Text>
<Binding Path="SabMax" ValidatesOnDataErrors="True" ValidatesOnExceptions="True" UpdateSourceTrigger="PropertyChanged" Mode="OneWayToSource"/>
</TextBox.Text>
</TextBox>
<ContentPresenter Grid.Row="1" Grid.Column="6" Content="{Binding ElementName=sabMaxTextBox, Path=(Validation.Errors).CurrentItem}"/>
#region IDataErrorInfo Members
string IDataErrorInfo.Error { get { return null; } }
string IDataErrorInfo.this[string propertyName]
{
get { return this.GetValidationError(propertyName); }
}
#endregion // IDataErrorInfo Members
string ValidateSabMin()
{
try
{
if (IsStringMissing(this.SabMin))
{
return "missing SAB MIN"; //TODO: Text der fehlermeldung in Ressource
}
else
{
if (!IsDouble(this.SabMin))
{
return "invalid input. only numeric value are allowed!"; //TODO: Text der fehlermeldung in Ressource
}
else
{
//eingabe valid. min und max vergleichen. min < max ?
if (!IsStringMissing(this.SabMax) && IsDouble(this.SabMax))
{
if (IsMinGreaterAsMax(this.SabMin, this.SabMax))
{
return "MIN > MAX !";
}
}
}
}
return null;
}
string ValidateSabMax()
{
if (IsStringMissing(this.SabMax))
{
return "missing SAB MAX"; //TODO: Text der fehlermeldung in Ressource
}
else
{
if (!IsDouble(this.SabMax))
{
return "invalid input. only numeric value are allowed!"; //TODO: Text der fehlermeldung in Ressource
}
else
{
//eingabe valid. min und max vergleichen. min < max ?
if (!IsStringMissing(this.SabMin) && IsDouble(this.SabMin))
{
if (IsMinGreaterAsMax(this.SabMin, this.SabMax))
{
return "MIN > MAX !";
}
}
}
}
return null;
}
das problem von dieser Lösung:
wenn ich z.B.
hat jemand eine idee was ich falsch mache oder wie ich das besser und eifacher umsetze
danke im voraus
Hallo sindibad,
das liegt daran wenn du den Text in der MinTextBox änderst wird nur die Validierung für die MinTextBox angestoßen. Die MaxTextBox wird nicht neu validiert und hat somit noch den "alten" Fehler.
Eine mögliche Lösung ist in deinem Fall das PropertyChanged Event für die Property die an die MaxTextBox gebunden ist zu feuern, dann müsste die TextBox eine erneute Validierung anwerfen.
Da musst du aber aufpassen das du keine Endlos Schleife erzeugst wenn du es umgekehrt genauso machst.
mfg,
XaN