Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > DatePicker > Disable RadDatePicker and RadTimePicker Default Validation in WPF

Not answered Disable RadDatePicker and RadTimePicker Default Validation in WPF

Feed from this thread
  • Martin avatar

    Posted on Jul 13, 2011 (permalink)

    Hello,

    I'm using xaml, view model and validation rule in C#

    The RadDatePicker has default validation for any invalid date. 

    In my xaml, I have my own validation rule for RadDatePicker and RadTimePicker with this Style of my ControlTemplate to display the error. (please see the xaml code below the for the Control Template Style and my validation rule)

    We allow the user to put nothing or empty string in the DatePicker unless we set it to mandatory that will use our validation rule to output a customized error style and message.In our validation rule, if we want to raise the error, it will use this code "return new ValidationResult(false, ErrorMessage);" However, since the default validation of RadDatePicker or RadTimePicker, it still set show the default error even the validation rule switches off the validation with this line  "return new ValidationResult(true, null);"

     Is there way I can disable the default behaviour and implement the custom behaviour I have?

    Thanks.

    Jason

    ====  Style of my ControlTemplate ==========

    <ControlTemplate x:Key="validationTemplate">
                    <DockPanel>
                        <TextBlock Foreground="Red" FontSize="20">!</TextBlock>
                        <AdornedElementPlaceholder/>
                    </DockPanel>
                </ControlTemplate>
                <Style x:Key="radDatePicker" TargetType="{x:Type telerik:RadDatePicker}">
                    <Style.Triggers>
                        <Trigger Property="Validation.HasError" Value="true">
                            <Setter Property="ToolTip"
                  Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                                  Path=(Validation.Errors)[0].ErrorContent}"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
                <Style x:Key="radTimePicker" TargetType="{x:Type telerik:RadTimePicker}">
                    <Style.Triggers>
                        <Trigger Property="Validation.HasError" Value="true">
                            <Setter Property="ToolTip"
                  Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                                  Path=(Validation.Errors)[0].ErrorContent}"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
      
    =================================================

    ==== xaml code to my validation rule ==========

     <telerik:RadDatePicker.SelectedDate>
                            <Binding Path="CommercialStartDateSelectedDate"
                                         UpdateSourceTrigger="PropertyChanged"
                                         Mode="TwoWay"
                                         >
                                <Binding.ValidationRules>
                        <common:MandatoryValidationRule
                                       
                                                ValidatesOnTargetUpdated="False"
                                                FieldName="CommercialStartDate" InstanceId="{common:DataResourceBinding DataResource={StaticResource commercialLayoutDesignInstanceId}}" IsMandatory="{common:DataResourceBinding DataResource={StaticResource commercialStartDateIsMandatory}}" ErrorMessage="{x:Static local:Globalization.CommercialStartDateMandatoryErrorMessage}" >
                        </common:MandatoryValidationRule>

                        <common:RecommendedValidationRule
                                                ValidatesOnTargetUpdated="False"
                                                IsRecommended="{common:DataResourceBinding DataResource={StaticResource commercialStartDateIsRecommended}}" ErrorMessage="{x:Static local:Globalization.CommercialStartDateRecommendedErrorMessage}" >
                        </common:RecommendedValidationRule>
                    </Binding.ValidationRules>


    Thanks,

    Reply

  • Pana Pana admin's avatar

    Posted on Jul 15, 2011 (permalink)

    Hello Martin,

    I am not sure I understand you well but from your description it sounds like you need to set the:

    Validation.ErrorTemplate="{x:Null}"

    On the RadDateTimePicker so the default red border does not appear.

    Kind regards,

    Pana
    the Telerik team

     

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > DatePicker > Disable RadDatePicker and RadTimePicker Default Validation in WPF
Related resources for "Disable RadDatePicker and RadTimePicker Default Validation in WPF"

WPF DatePicker Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]