This is a migrated thread and some comments may be shown as answers.

Validation of property on keypress

1 Answer 113 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Canice asked on 02 Sep 2019, 01:23 PM



Is it possible to perform validation on keypress instead of lost focus, similar to UpdateSourceTrigger in WPF?

I'm using the WPF RadPropertyGrid control with AutoGeneratePropertyDefinitions set to true.


                    <t:RadPropertyGrid Name="VdiPropertyGrid"  Grid.Column="2" 
                                      Item="{Binding Path=DataContext.SelectedPropertyInspector, RelativeSource={RelativeSource FindAncestor,  AncestorType={x:Type UserControl}}}"
                                      HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"    IsGrouped ="True"                        
                                      ScrollViewer.CanContentScroll="False" ScrollViewer.VerticalScrollBarVisibility="Auto"
                                      DescriptionPanelVisibility="Visible" SearchBoxVisibility="Visible" ForceCursor="True" SelectionMode="Single" 
                                      AutoGeneratingPropertyDefinition="RadPropertyGrid_OnAutoGeneratingPropertyDefinition" ItemChanged="VdiPropertyGrid_ItemChanged"    >

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




1 Answer, 1 is accepted

Sort by
Dinko | Tech Support Engineer
Telerik team
answered on 05 Sep 2019, 08:33 AM
Hi Canice,

Thank you for the provided code snippet.

Looking at the code snippet you have subscribe to the AutoGeneratingPropertyDefinition event. Can you try adding the following code inside the event handler? In a few words I am using the Binding property of the PropertyDefinition and setting the UpdateSourceTrigger to PropertyChanged
void RadPropertyGrid_OnAutoGeneratingPropertyDefinition(object sender, Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs e)
    //  IDataErrorInfo
    (e.PropertyDefinition.Binding as Binding).ValidatesOnDataErrors = true;
    (e.PropertyDefinition.Binding as Binding).NotifyOnValidationError = true;
    (e.PropertyDefinition.Binding as Binding).UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
    //// DataAnnotations
    (e.PropertyDefinition.Binding as Binding).ValidatesOnExceptions = true;

In addition, you can check our RadPropertyGrid Validation SDK example in our GitHub repository.

Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Asked by
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question