<Window x:Class="DotnetBullet.WPFValidationWay1.MainWindow"    
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
        xmlns:c="clr-namespace:DotnetBullet.WPFValidationWay1"
        xmlns:wpfApplication1="clr-namespace:WpfApplication1"
        Title="مرجع تخصصی برنامه نویسان " Height="250" Width="450">

    <Window.Resources>
        <wpfApplication1:User x:Key="user"/>
        <ControlTemplate x:Key="validationTemplate">
            <DockPanel>
                <TextBlock Foreground="Red" FontSize="25" Text="*" DockPanel.Dock="Right"></TextBlock>
                <AdornedElementPlaceholder/>
            </DockPanel>
        </ControlTemplate>

        <Style x:Key="InputControlErrors" TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip"    
              Value="{Binding RelativeSource={x:Static RelativeSource.Self},    
                              Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <Grid Margin="0,0,0,5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="4*"/>
            <ColumnDefinition Width="13*"/>
        </Grid.ColumnDefinitions>
        <Label Content="نام " HorizontalAlignment="Left" Margin="42,10,0,0" VerticalAlignment="Top"/>
        <Label Content="سن " HorizontalAlignment="Left" Margin="42,67,0,0" VerticalAlignment="Top"/>
        <Label Content="همراه " HorizontalAlignment="Left" Margin="42,127,0,0" VerticalAlignment="Top"/>

        <TextBox HorizontalAlignment="Left" Height="23" Margin="55,14,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="258"     
                 Validation.ErrorTemplate="{StaticResource validationTemplate}" Style="{StaticResource InputControlErrors}"    
                 Name="txtName" Grid.Column="1">
            <TextBox.Text>
                <Binding Path="UserName" Source="{StaticResource user}" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <wpfApplication1:RequiredFiedValidationRule></wpfApplication1:RequiredFiedValidationRule>
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>

        </TextBox>

        <TextBox HorizontalAlignment="Left" Height="23" Margin="55,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="258"    
                 Validation.ErrorTemplate="{StaticResource validationTemplate}" Style="{StaticResource InputControlErrors}"    
                 Name="txtAge" Grid.Column="1">
            <TextBox.Text>
                <Binding Path="Age" Source="{StaticResource user}" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <wpfApplication1:RequiredFiedValidationRule></wpfApplication1:RequiredFiedValidationRule>
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <TextBox HorizontalAlignment="Left" Height="23" Margin="55,130,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="258"    
                 Validation.ErrorTemplate="{StaticResource validationTemplate}" Style="{StaticResource InputControlErrors}"    
                 Name="txtMobileNo" Grid.Column="1">
            <TextBox.Text>
                <Binding Path="MobileNo" Source="{StaticResource user}" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <wpfApplication1:RequiredFiedValidationRule></wpfApplication1:RequiredFiedValidationRule>
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>

        </TextBox>

    </Grid>
</Window> 