---
title: "How to show WPF ValidationResult in a seperate textblock?"  
description: "How to show WPF ValidationResult in a seperate textblock?"  
author: "Anonymous User"  
published: 2013-09-21  
updated: 2013-09-21  
canonical: https://www.mindstick.com/forum/1467/how-to-show-wpf-validationresult-in-a-seperate-textblock  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# How to show WPF ValidationResult in a seperate textblock?

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to use in WPF a validating input of databound [controls](https://www.mindstick.com/articles/66/how-to-create-controls-at-run-time-in-csharp-dot-net) with [validation rules](https://www.mindstick.com/forum/158293/is-it-possible-to-create-custom-validation-rules-using-jquery-validation-if-so-how). I have a posintValidationRule class:

```
       public class posintValidationRule : ValidationRule{    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)    {        string _strInt = value.ToString();        int _int = -1;        if (!Int32.TryParse(_strInt, out _int))            return new ValidationResult(false, "Value must be an integer");        if (_int < 0)            return new ValidationResult(false, "Value must be positive");        return new ValidationResult(true, null);    }}
```

**In XAML there is also a [style](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment) error [template](https://www.mindstick.com/blog/282/creating-custom-template-in-joomla):**

```
   <Setter Property="Validation.ErrorTemplate">     <Setter.Value>        <ControlTemplate>          <StackPanel>            <Border BorderBrush="Red" BorderThickness="1" >               <AdornedElementPlaceholder></AdornedElementPlaceholder>            </Border>            <TextBlock Text="there is an error"></TextBlock>           </StackPanel>         </ControlTemplate>     </Setter.Value>   </Setter>  <Style.Triggers>     <Trigger Property="Validation.HasError" Value="true">        <Setter            Property="ToolTip"            Value="{Binding RelativeSource={RelativeSource Self},            Path=(Validation.Errors)[0].ErrorContent}"/>        </Trigger>    </Style.Triggers>
```

When [validation error](https://www.mindstick.com/forum/156619/validation-error-in-a-text-field-with-the-help-of-bootstrap) occurs, the text of ValidationResult from posintValidationRule class appears in a [tooltip](https://www.mindstick.com/articles/1529/simple-tooltip-using-html-css) ("Value must be an [integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer)" and the like).

How I could have this the same text shown in a TextBlock from a Validation.ErrorTemplate which now, in case of an error, says just: "there is an error"?

## Replies

### Reply by Sumit Kesarwani

Hi Jeet,\

I have found the solution:

```
<Style TargetType="{x:Type TextBox}">       <Setter Property="Validation.ErrorTemplate">       
<Setter.Value>           
<ControlTemplate>             
<StackPanel>               
<Border BorderBrush="Red" BorderThickness="1" Margin="5,0,5,0" >                    <AdornedElementPlaceholder Name="MyAdorner" ></AdornedElementPlaceholder>               
</Border>               
<TextBlock                    
Margin="5,0,0,0"                     
Foreground="Red"                      
Text="{Binding ElementName=MyAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">              
</TextBlock>            
</StackPanel>          
</ControlTemplate>      
</Setter.Value>     </Setter></Style>
```


---

Original Source: https://www.mindstick.com/forum/1467/how-to-show-wpf-validationresult-in-a-seperate-textblock

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
