Custom control validation on dependency property using masked input

2 posts, 0 answers
  1. Alexandre
    Alexandre avatar
    1 posts
    Member since:
    Aug 2017

    Posted 01 Sep Link to this post

    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 custom 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 through 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

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1408 posts

    Posted 06 Sep Link to this post

    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.
Back to Top