Hello, I am trying to use the RadMaskedNumericInput control for masking text and binding on some customer data, such as phone numbers. I have found this control to be extremely buggy and unusable.
I am using a custom mask "(###) ###-####" and it works fine. The phone numbers are stored as 10 digit strings with no separators ("0123456789" for example). When I load a customer, the value shows up correctly masked in the control (I see (012) 345-6789).
The main problem is that the bound property on the model never gets set. So if I am entering a new customer and type in the phone number, it does not get saved. I found that this is because the Value property of the numeric input never gets changed, as the conversion from string always fails. I have tried setting ValueToTextConverter to convert between double? and string, and I found that when NumericInput attempts to convert what is typed and store it the double? Value property, it always includes the mask in the string it's trying to convert. So it tries to convert "(012) 345-6789" to a double and this of course fails. I have tried binding to the Text property instead, but this does not work either as it includes the characters from the mask.
I have TextMode set to MaskedText, please do not recommend that as the solution because it does not work. I have tried setting it in markup and via an extended class. If I set it in markup, the typed text will stay in the control, but still the values will never be set. If I set TextMode via the extended class, the typed characters will disappear when the control loses focus, though they will reappear when it regains focus. But still the databinding will not set the model's properties.
I am using release 2011.3.1116.40 and unfortunately upgrading is not possible as this is the version provided and required by my client.
Here is the code for the value converter I used with MaskedNumericInput:
Here is a XAML sample:
I am using a custom mask "(###) ###-####" and it works fine. The phone numbers are stored as 10 digit strings with no separators ("0123456789" for example). When I load a customer, the value shows up correctly masked in the control (I see (012) 345-6789).
The main problem is that the bound property on the model never gets set. So if I am entering a new customer and type in the phone number, it does not get saved. I found that this is because the Value property of the numeric input never gets changed, as the conversion from string always fails. I have tried setting ValueToTextConverter to convert between double? and string, and I found that when NumericInput attempts to convert what is typed and store it the double? Value property, it always includes the mask in the string it's trying to convert. So it tries to convert "(012) 345-6789" to a double and this of course fails. I have tried binding to the Text property instead, but this does not work either as it includes the characters from the mask.
I have TextMode set to MaskedText, please do not recommend that as the solution because it does not work. I have tried setting it in markup and via an extended class. If I set it in markup, the typed text will stay in the control, but still the values will never be set. If I set TextMode via the extended class, the typed characters will disappear when the control loses focus, though they will reappear when it regains focus. But still the databinding will not set the model's properties.
I am using release 2011.3.1116.40 and unfortunately upgrading is not possible as this is the version provided and required by my client.
Here is the code for the value converter I used with MaskedNumericInput:
[CanConvert(
typeof
(System.String),
typeof
(System.Nullable<
double
>))]
public
class
StringToNullableDouble : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
string
s = value
as
string
;
if
(s ==
null
)
return
null
;
double
d;
if
(Double.TryParse(s,
out
d))
return
d;
return
null
;
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
double
? d = value
as
double
?;
if
(d ==
null
|| !d.HasValue)
return
null
;
return
d.Value.ToString();
}
}
Here is a XAML sample:
<
tel:RadMaskedNumericInput
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Center"
EmptyContent
=
"Enter Phone"
Width
=
"120"
Margin
=
"2"
Mask
=
"(###) ###-####"
Value
=
"{Binding Path=Customer.Phone, ValidatesOnDataErrors=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
FontWeight
=
"Bold"
AllowInvalidValues
=
"False"
AutoFillNumberGroupSeparators
=
false
;
AutoFillZeros
=
"False"
FlowDirection
=
"LeftToRight"
Precision
=
"0"
HorizontalContentAlignment
=
"Left"
TextMode
=
"MaskedText"
SpinMode
=
"None"
/>