Data binding with RadMaskedTextInput

9 posts, 0 answers
  1. Anthony
    Anthony avatar
    41 posts
    Member since:
    Apr 2012

    Posted 09 Dec 2013 Link to this post

    I want the value with the formatting characters. I was under the impression that I could bind to the Text property of the RadMaskedTextInput to do just that. However, the data binding doesn't work. It works fine if I bind to the Value property, but I don't get the formatting characters I want.
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 12 Dec 2013 Link to this post

    Hello Anthony,

    The RadMaskedInputControls are designed to work with their Value property. Value is of type string in TextInput, double? in NumericInput, decimal? in CurrencyInput and DateTime? in DateTimeInput. The Text property is of type string and it returns actually the string you see when focus is lost - Text is result of the combination of Value, Mask, PlaceHolder, TextMode. You can consider Text as only a getter property , setting it is possible but won't do nothing - won't actually change the Value.
    Could you please elaborate more on your particular scenario - what do you need to save as a value and what do you need to be displayed as a string? This way we would be better able to help you. Probably this requirement could be achieved with combination no-mask, FormatString or something similar. We would be glad to help you further.

    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Anthony
    Anthony avatar
    41 posts
    Member since:
    Apr 2012

    Posted 12 Dec 2013 Link to this post

    I'm using it to store a value in a phone number field. There's a corresponding country code used in a trigger and if the country code is 1 then I apply a mask in order to enforce a specific format. However, it's important that the formatting characters are stored for readability. That is, I want to store and use (678) 555-1234 not 6785551234.


    Everything except the binding to the Text property works.

  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 17 Dec 2013 Link to this post

    Hello Anthony,

    Let's suppose you have the string "(678)555-1234" in the database. Generally you have two options:
    • Use RadMaskedTextInput with Mask="" (no-mask). Then bind the Value two-way to the db string. 
    Value is of type string and you will always have the same typed string both in the Value and in the DB.
    The negative effect of this approach is that you have to type the brackets and the minus symbol manually.
     
    • Use RadMaskedNumericInput / RadMaskedTextInput with Mask = "(d3)d3-d3". Bind the Value to the dbString one way with converter:
    Value = {Binding dbString, Mode=TwoWay, Converter={StaticResource converter }}
    The converter has to remove the brackets and the minus from the string "(678)555-1234" and has to produce the double / string 6785551234. In the convert back method the converter have to add the brackets and the minus sign. Instead of two way binding the Value and converter with two directions you can also bind the Value one way (value will get the string from he DB) and bind the Text OneWayToSource (Text will always preserve the brackets and the minus). But the cleaner approach is to bind the Value two-way.

    We hope this will help you proceed further.






    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Anthony
    Anthony avatar
    41 posts
    Member since:
    Apr 2012

    Posted 24 Dec 2013 Link to this post

    Thank you. I used a converter in conjunction with a DataTrigger (since I didn't want to use the mask if the country code wasn't 1). It's behaving the way I want now.


    Here's a trimmed down version of my XAML in case this is useful for anyone else.



    <Style x:Key="PhoneFormatStyle" TargetType="{x:Type telerik:RadMaskedTextInput">

         <Setter Property="Value" Value={Binding ...}" />

         <Setter Property="Mask Value="" />

         ...

         <Style.Triggers>

              <DataTrigger Binding={Binding ...} Value="1">

                   <Setter Property="Value" Value="{Binding ..., Converter={StaticResource PhoneFormatConverter}}" />

                   <Setter Property="Mask" Value="(d3) d3-d4" />

              </DataTrigger>

         </Style.Triggers>

    </Style>

  7. Jeff
    Jeff avatar
    25 posts
    Member since:
    Feb 2009

    Posted 28 Feb 2014 Link to this post

    We use a dynamic mask and are also looking for similar behavior. Since our mask is not hard coded it would be difficult to write a converter that basically duplicates the inner functionality of the RadMaskedTextInput control. What would be really great is is there was some type of FormattedValue or ValueWithLitterals property that could be bound to that would essentially do the conversion based on the mask. Pretty much all of our masked text controls in our software need to work this way and in many cases the masks are user definable or depend on cultures and locale in a way that would be very burden to reproduce the masking behavior. I'm hoping there may be some way this could be provided as an additional feature to the RadMaskedTextInput control even if it it's just an officially supported attached property that has access to the same internal masking syntax code.
  8. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 05 Mar 2014 Link to this post

    Hi Jeff,

    In order to log a feature request in our system, or to help you with a possible solution, could you please elaborate a bit more on your particular scenarios ? You can send us your top 3 popular scenarios - what masks do you use in them, what formatting and conversion do you need and what kind of values do you save / use ? Thank you in advance for your cooperation.

    Regards,
    Petar Mladenov
    Telerik

    DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

  9. Anthony
    Anthony avatar
    41 posts
    Member since:
    Apr 2012

    Posted 05 Mar 2014 in reply to Petar Mladenov Link to this post

    Petar,

    Simply put I want the ability to databind to the Text property, so that I can get the formatting characters included.

    One particular scenario is that the phone numbers are going to have different formats in different locations. However, you may not want to store just a set of numbers and have to replicate the formatting logic to other systems (especially reporting) that use the data. The same thing can apply to other areas like postal codes.
  10. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 07 Mar 2014 Link to this post

    Hello Anthony,

    You can vote for this related feature request and this way you will increase its development priority.

    Regards,
    Petar Mladenov
    Telerik

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

Back to Top
UI for WPF is Visual Studio 2017 Ready