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

Custom control validation on dependency property using masked input

1 Answer 406 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Alexandre
Top achievements
Rank 1
Alexandre asked on 01 Sep 2017, 08:21 PM

Hi

We have implemented a validation through data annotation on a RadMaskedTextInput using this link: http://docs.telerik.com/devtools/wpf/controls/radmaskedinput/features/validation/regex

We are having an issue when we are implementing it with a custom control.

 

In the provided solution when RadMaskedTextInput, one is provided through the  control and the other one is directly in the MainWindow.

The first RadMaskedTextInput (from the custom control) does not validate the data.

The second RadMaskedTextInput is validating the data when we are directly typing in it.

we suspect that it is related to the fact that we are binding a dependency property

How can we modify the custom control to trigger the validation on the property?

Thank you for your help

Alexandre

Solution

https://drive.google.com/open?id=0B46KQ0X-Kpsddk1CWmcyeXV3bzg

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 06 Sep 2017, 12:17 PM
Hello Alexandre,

This behavior comes from the WPF framework and it can be reproduced also with a native TextBox element. It happens because the validation is not forwarded to the binding on the UserControl level. In other words the error doesn't get to the masked input control because the framework requires to be bound directly to the model's property.

There are couple of approaches which I can suggest.
  • The first one is to bind the Value property of the masked input control from the UserControl directly to the viewmodel property.
  • The other approach is to create a ValidationRule for each property that should be validated in the UserControls and set it in the Value Binding's ValidationRules collection. You can see how to do that in the MSDN documentation.

I hope this information helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Alexandre
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or