RadMaskedNumericInput with TwoWay binding not displaying current value

5 posts, 0 answers
  1. Peter
    Peter avatar
    6 posts
    Member since:
    Jan 2013

    Posted 20 Jan 2013 Link to this post

    Hi, I am currently having problems with the RadMaskedNumericInput control not displaying the current bound value.

    Here is the xaml for the control

    <telerik:RadMaskedNumericInput Mask="" HorizontalAlignment="Stretch"
        IsEnabled="{Binding IsUpdatable}" Value="{Binding Value, Mode=TwoWay}"
        SelectionOnFocus="SelectAll" TextMode="PlainText" UpdateValueEvent="PropertyChanged"
                <TextBlock Text="Enter a number" FontStyle="Italic"
                    IsHitTestVisible="False" Opacity="0.5" />

    This field is bound to the following property on viewmodel extending ViewModelBase

    public Object Value {
        get { return this.value; }
        set {
            this.value = value;

    At runtime this Value is set to an integer in behind code yet the control displays 0.

    I have stepped through the code and the correct integer value is being returned by the getter and can still be set correctly from the control, however it appears as though it cannot be set from behind code and the binding is not being updated.

    Any suggestions are appreciated.
  2. Petar Mladenov
    Petar Mladenov avatar
    3152 posts

    Posted 23 Jan 2013 Link to this post

    Hi Peter,

     RadMaskedNumericInput's Value property is of type nullable double (double?) and you have to bind it to ViewModel's property of type double or nullable double (if you need to set null). Binding to object is not support and may result in unpredictable behavior. Is there any specific reason for you to use Object for the type of the ViewModel's "Value" property?

    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Peter
    Peter avatar
    6 posts
    Member since:
    Jan 2013

    Posted 23 Jan 2013 Link to this post

    Unfortunately in our situation there isn't a feasible way around an Object type for the Value property.

    I think instead I'll go with RadTextBox controls with converters.

    Thank you for your help
  4. J
    J avatar
    143 posts
    Member since:
    Jun 2006

    Posted 15 Jul 2013 Link to this post

    Petar, I'm having some difficulty with this RadMaskedNumericInput control too.  I have the following control:
    <telerik:RadMaskedNumericInput Grid.Column="3" Grid.Row="1" Mask="n3.3" IsClearButtonVisible="True"
    UpdateValueEvent="PropertyChanged" SelectionOnFocus="SelectAll"
    AllowSkipPlaceholders="True" Value="{Binding myDoubleValue, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}"
    TextMode="PlainText" x:Name="txtUnits" />

    My question is?  Why do I need to type in a value in the format of ###.### to get this control to save correctly?  Is it cause I'm setting the property Mask to "n3.3"?

  5. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 17 Jul 2013 Link to this post

    Hi J,

    The RadMaskedInput controls are designed to create a predefined input for a user. Basically as soon as you apply a Mask property, this property is used to assert whether the entered value is valid or not. And by valid I mean that it matches the predefined mask.

    This is why when you apply a Mask of "n3.3", you tell the control that its value is valid and correct only when it contains 3 digits before and 3 digits after the floating point. And only when this criteria is met, the value is processed as appropriate and the underlying ViewModel is updated accordingly.

    If you want to workaround this behavior, we've exposed a property in the RadMaskedNumericInput - AllowInvalidValues. Its default value is false which means that until a value matches the criteria applied by the Mask property, it isn't considered as valid and the ViewModel isn't updated. But as soon as you set the AllowInvalidValues property to True, the MaskedNumericInput will start updating its value and the corresponding business property at every new input disregarding the Mask restrictions.

    And in your case, you can try setting the AllowInvalidValues to True as this should lead to the results you requested. Also, I noticed that your Value binding Mode isn't TwoWay so you might want to consider changing that as well. A TwoWay mode allows the MaskedNumericInput control to update the business model underneath it accordingly.

    I hope this information helps but please don't hesitate to write back if you have other questions.

    Tina Stancheva
    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 >>
Back to Top