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

Can't set mask of RadMaskedCurrencyInput by NumberFormat.CurrencyDecimalDigits of CurrentThread

1 Answer 56 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
tungnt185
Top achievements
Rank 2
tungnt185 asked on 24 Mar 2011, 10:14 AM
Hi Telerik team.

I'm using RadMaskedCurrencyInput for replacing RadMaskedTextBox.
I've formated the RadMaskedCurrencyInput by NumberFormat of CurrentThread.
Everything work fine like CurrencySymbol,
CurrencyDecimalSeparator, CurrencyGroupSeparator except CurrencyDecimalDigits.

I know the control using Mask property for masking input but I think it's a good solution is ability to formating this property automatically follow CurrencyDecimalDigits.

Now Mask default value is #9.2 and I must go to every control for reset it manually.
Are there have anyway to resolve this?

Regards.

1 Answer, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 24 Mar 2011, 12:38 PM
Hi Taufik Hidayat,

You can create an attached property for the currency input control which will change the mask according to the current culture. Here is a sample code that you can use :

<telerik:RadMaskedCurrencyInput xmlns:ext="clr-namespace:MaskExtensions" ext:MaskHelper.UseCurrencyDigits="True"/>

namespace MaskExtensions
{
    public class MaskHelper : DependencyObject
    {
        // ... attached property get/set methods

        public static readonly DependencyProperty UseCurrencyDigitsProperty =
            DependencyProperty.RegisterAttached("UseCurrencyDigits", typeof(bool), typeof(RadMaskedInputBase), new PropertyMetadata(false, new PropertyChangedCallback(OnUseCurrencyDigitsChanged) ));
        private static void OnUseCurrencyDigitsChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            if ((bool)args.NewValue == true)
            {
                RadMaskedCurrencyInput owner = d as RadMaskedCurrencyInput;
                owner.Loaded += (s, e) =>
                    {
                        string currentMask = owner.Mask;
                        owner.Mask = "c9." + Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalDigits.ToString();
                    };
            }
        }
    }
}

Please also note, that with the latest internal builds the culture of the control will default to the current culture, and not to en-US.

All the best,
Alex Fidanov
the Telerik team
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
tungnt185
Top achievements
Rank 2
Answers by
Alex Fidanov
Telerik team
Share this question
or