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,
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,