xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WpfApplication1="clr-namespace:WpfApplication1"
    Title="WPF" Height="100" Width="280">
    
                    x:Key="textBoxInErrorStyle" 
            TargetType="{x:Type TextBox}" >
            
                
                    
                                Path=(Validation.Errors)[0].ErrorContent}"/>
                
            
            
                
                    
                        
                            
                            
                                            Mode=FindAncestor,
                                            AncestorType={x:Type Adorner}}}"/>
                        
                    
                
            
        
    
    
        
        
            
              
                    
                       
                            
                        
                    
                
            
        
    
//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