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

2 posts, 0 answers
  1. tungnt185
    tungnt185 avatar
    40 posts
    Member since:
    Aug 2009

    Posted 24 Mar 2011 Link to this post

    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.

  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 24 Mar 2011 Link to this post

    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
  3. DevCraft banner
Back to Top