Geysser
Member
- Joined
- Apr 6, 2010
- Messages
- 17
- Programming Experience
- 5-10
I have a problem with validating a text field (and, being a WPF novice, please be gentle!)
My textbox is as follows:
...and the validator is this:
When I type a number within the range, I get a StackOverflowException.
What could there be wrong?
My textbox is as follows:
HTML:
<TextBox x:Name="PiecesSText" TextAlignment="Right"
Width="50" Height="18"
HorizontalAlignment="Left" VerticalAlignment="Top"
Margin="42,129,0,0" Style="{StaticResource FlatTextBoxStyle}">
<TextBox.Text>
<Binding RelativeSource="{RelativeSource Self}"
Path="Text" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<val:PieceNumValidator Min="1" Max="20"
ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules
</Binding>
</TextBox.Text>
</TextBox>
...and the validator is this:
VB.NET:
Public Class PieceNumValidator : Inherits ValidationRule
Public Property Min As Int16
Public Property Max As Int16
Public Overrides Function Validate(value As Object,
cultureInfo As System.Globalization.CultureInfo) _
As System.Windows.Controls.ValidationResult
Dim iParam As Int16 = 0
If value.ToString.Length <> 0 Then
If IsNumeric(value) = True Then
iParam = Int16.Parse(value.ToString)
Else
Return New ValidationResult(False, "Invalid data type!")
End If
Else
Return New ValidationResult(False, "No data!")
End If
If iParam < Min Or iParam > Max Then
Return New ValidationResult(False, "Param out of range!")
Else
Return New ValidationResult(True, Nothing)
End If
End Function
End Class
When I type a number within the range, I get a StackOverflowException.
What could there be wrong?