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

RadMaskedNumericInput with TwoWay binding not displaying current value

4 Answers 325 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 21 Jan 2013, 02:23 AM
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"
    maskedInput:MaskedInputExtensions.Maximum="2147483646"
    maskedInput:MaskedInputExtensions.Minimum="0"
    HorizontalContentAlignment="Left">
        <telerik:RadMaskedNumericInput.EmptyContent>
            <TextBlock Text="Enter a number" FontStyle="Italic"
                IsHitTestVisible="False" Opacity="0.5" />
        </telerik:RadMaskedNumericInput.EmptyContent>
</telerik:RadMaskedNumericInput>

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

public Object Value {
    get { return this.value; }
    set {
        this.value = value;
        OnPropertyChanged("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.

4 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 23 Jan 2013, 04:26 PM
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?

Greetings,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Peter
Top achievements
Rank 1
answered on 24 Jan 2013, 01:01 AM
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
0
J
Top achievements
Rank 1
answered on 15 Jul 2013, 05:54 PM
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"?

J
0
Tina Stancheva
Telerik team
answered on 17 Jul 2013, 04:52 PM
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.

Regards,
Tina Stancheva
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
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 >>
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Peter
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Peter
Top achievements
Rank 1
J
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or