Ketul
Ketul

Reputation: 3

WPF Validation for TextBlock

Just Making a WPF Desktop Application. I am Using various validations. In TextBox if I am using , NotifyOnValidationError=True,ValidatesOnDataErrors=True,ValidatesOnExceptions=True Its working fine.But in TextBlock if I am using the same thing the whole block is highlighted with red sign .... i just want an excla. (!) mark ..NotifyOnValidationError=True,ValidatesOnDataErrors=True,ValidatesOnExceptions=True. what should i do ?

Upvotes: 0

Views: 1015

Answers (1)

Dan Carlstedt
Dan Carlstedt

Reputation: 311

If you want to override the default error template defined in the Validation class you can simply define a ControlTemplate and assign that to the TextBlock Validation.ErrorTemplate attached property.

<TextBlock
Validation.ErrorTemplate="{StaticResource TextBlockErrorTemplate}">     
<TextBlock>

Within a Resource dictionary you can define an error template like so:

 <ControlTemplate x:Key="TextBlockErrorTemplate">
            <DockPanel LastChildFill="True">
                <TextBlock DockPanel.Dock="Right"
                           Foreground="Red"
                           FontSize="14pt"
                           Margin="-15,0,0,0"
                           FontWeight="Bold">!
                </TextBlock>
                <AdornedElementPlaceholder Name="controlWithError" />
            </DockPanel>
        </ControlTemplate>

Upvotes: 1

Related Questions