Hallo Leute,
ich möchte die Eingabe in eine Textbox mittels ValidationRule prüfen.
Die Eingegebene Zahl soll bestimmte Min/Max Werte nicht überschreiten und vom Typ Single sein.
Mein Problem ist, dass wenn ich in das Textfeld ein Komma eingebe und anschließend die Zahl nach dem Komma, das Komma dann wieder verschwindet.
Beispiel der Wert soll '12,3' sein. sobald ich die '3' eingebe steht in der Box '123'. Ich verstehe nicht was mir immer das Komma raus löscht.
Hier der Code des "Validators":
Public Class SingleDataValidator
Inherits ValidationRule
Public Sub New()
Me.Minimum = 0
Me.Maximum = 1
End Sub
Public Property Minimum() As Single
Get
Return m_Minimum
End Get
Set(value As Single)
m_Minimum = value
End Set
End Property
Private m_Minimum As Single
Public Property Maximum() As Single
Get
Return m_Maximum
End Get
Set(value As Single)
m_Maximum = value
End Set
End Property
Private m_Maximum As Single
Public Overrides Function Validate(value As Object, cultureInfo As _
System.Globalization.CultureInfo) As _
System.Windows.Controls.ValidationResult
If value Is Nothing Then
Return New ValidationResult(False, "Falsche Eingabe")
End If
Dim i As Single = 0
Try
i = CSng(value)
Catch ex As Exception
Return New ValidationResult(False, "Falsche Eingabe")
End Try
'If Not Single.TryParse(value, i) Then
' Return New ValidationResult(False, "Falsche Eingabe")
'End If
If i >= Me.Minimum AndAlso i <= Me.Maximum Then
Return New ValidationResult(True, Nothing)
Else
If i >= Me.Minimum Then
Return New ValidationResult(False, "Zu groß!")
Else
Return New ValidationResult(False, "Zu klein!")
End If
End If
End Function
End Class Und hier die Einbindung in WPF:
<TextBox x:Name="txbTEMP_SETBACK" Grid.Row="3" Grid.Column="1" Width="120" _
HorizontalAlignment="Left" Margin="10,0,0,0" FontSize="10.667" _
VerticalAlignment="Center" FontWeight="Normal" >
<TextBox.Text>
<Binding Path="TEMP_SETBACK" Mode="TwoWay" _
UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<validator:SingleDataValidator Minimum="10.0" _
Maximum="30.0"/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox> |