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

Validation of property on keypress

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

 

Hello,

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" 
                                      AutoGeneratePropertyDefinitions="True"                                   
                                      AutoGeneratingPropertyDefinition="RadPropertyGrid_OnAutoGeneratingPropertyDefinition" ItemChanged="VdiPropertyGrid_ItemChanged"    >

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


                        </t:RadPropertyGrid.Resources>
                    </t:RadPropertyGrid>

 

Regards,
Canice.

1 Answer, 1 is accepted

Sort by
0
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.

Regards,
Dinko
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.
Tags
PropertyGrid
Asked by
Canice
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or