Mega Code Archive
Specify Validation Rules for a Binding
//File:Window.xaml.vb
Imports System.Globalization
Imports System.Windows.Controls
Namespace WpfApplication1
Public Class PercentageRule
Inherits ValidationRule
Public Overrides Function Validate(value As Object, cultureInfo As CultureInfo) As ValidationResult
Dim stringValue As String = TryCast(value, String)
If Not String.IsNullOrEmpty(stringValue) Then
Dim doubleValue As Double
If Double.TryParse(stringValue, doubleValue) Then
If doubleValue >= 0 AndAlso doubleValue <= 100 Then
Return New ValidationResult(True, Nothing)
End If
End If
End If
Return New ValidationResult(False, "Must be a number between 0 and 100")
End Function
End Class
End Namespace