I have a TextBox bound to some property. I have implemented IDataErrorInfo for performing validation. Recently I was seeing some control in web which shows an error like a red triangle. I have attached the sample below:
I know I have to write error template to display this whenever an error occurs. When the user hovers the red triangle, it will display the error message in ToolTip. How do I display an error textBox like the one I have uploaded. How to get the red triangle in error template?
Here is an example that looks like this
Use it like
<TextBox Validation.ErrorTemplate="{StaticResource topRightCornerErrorTemplate}"
.../>
ErrorTemplate
<ControlTemplate x:Key="topRightCornerErrorTemplate">
<Grid>
<Polygon Points="40,20 40,0 0,0"
Stroke="Black"
StrokeThickness="1"
Fill="Red"
HorizontalAlignment="Right"
VerticalAlignment="Top"
ToolTip="{Binding ElementName=adorner,
Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"/>
<AdornedElementPlaceholder x:Name="adorner"/>
</Grid>
</ControlTemplate>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With