Exemple #1
0
        static void OnNumberOfDecimalDigitChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            DecimalBox me = sender as DecimalBox;

            if (me != null)
            {
                if (string.IsNullOrEmpty(me.DisplayFormat))
                {
                    string wrk = string.Empty;
                    if (me.MaxNumber != null)
                    {
                        wrk = "0".PadLeft(Math.Floor(me.MaxNumber.Value).ToString(System.Globalization.CultureInfo.CurrentCulture).Length, '#');
                    }
                    else
                    {
                        int padLen = me.MaxLength;

                        if (me.NumberOfDecimalDigit != null && me.NumberOfDecimalDigit.Value > 0)
                        {
                            padLen -= me.NumberOfDecimalDigit.Value;
                        }
                        wrk = "0".PadLeft(padLen, '#');
                    }

                    if (me.NumberOfDecimalDigit != null)
                    {
                        if (me.NumberOfDecimalDigit.Value > 0)
                        {
                            wrk += ".".PadRight(me.NumberOfDecimalDigit.Value + 1, '0');
                        }
                    }
                    me.DisplayFormat = wrk;
                }
            }
        }
Exemple #2
0
        static void OnDisplayFormatChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            DecimalBox me = sender as DecimalBox;

            if (me != null)
            {
                me.SetDisplay();
            }
        }
Exemple #3
0
        static object OnCoerceValueChanged(DependencyObject sender, object value)
        {
            decimal    retVal        = (decimal)value;
            DecimalBox me            = sender as DecimalBox;
            bool       valueModified = false;

            if (me != null)
            {
                if (me.MaxNumber != null)
                {
                    if (retVal > me.MaxNumber.Value)
                    {
                        retVal        = me.MaxNumber.Value;
                        valueModified = true;
                    }
                }
                if (me.MinNumber != null)
                {
                    if (retVal < me.MinNumber.Value)
                    {
                        retVal        = me.MinNumber.Value;
                        valueModified = true;
                    }
                }
                if (me.NumberOfDecimalDigit != null)
                {
                    string[] wrk     = retVal.ToString(System.Globalization.CultureInfo.CurrentCulture).Split('.');
                    int      numDigs = 0;
                    if (wrk.Length > 1)
                    {
                        numDigs = wrk[1].Length;
                    }
                    if (numDigs > me.NumberOfDecimalDigit.Value)
                    {
                        retVal        = Math.Floor(decimal.Multiply(retVal, Convert.ToDecimal(Math.Pow(10, me.NumberOfDecimalDigit.Value)))) / Convert.ToDecimal(Math.Pow(10, me.NumberOfDecimalDigit.Value));
                        valueModified = true;
                    }
                }
                if (valueModified)
                {
                    me.WorkValue = retVal.ToString(System.Globalization.CultureInfo.CurrentCulture);


                    me.SetDisplay();
                }
            }
            return(retVal);
        }
Exemple #4
0
        static void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            DecimalBox me = sender as DecimalBox;

            if (me != null)
            {
                if (!me.SettingValues)
                {
                    me.SettingValues = true;
                    me.WorkValue     = me.Value.ToString(System.Globalization.CultureInfo.CurrentCulture);
                    me.SettingValues = false;
                }
                me.SetDisplay();
                me.RaiseEvent(new RoutedEventArgs(ValueChangedEvent));
            }
        }
Exemple #5
0
        static void OnWorkValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            DecimalBox me = sender as DecimalBox;

            if (me != null)
            {
                if (!me.SettingValues)
                {
                    me.SettingValues = true;
                    decimal wrk = me.Value;
                    if (decimal.TryParse(me.WorkValue, out wrk))
                    {
                        me.Value = wrk;
                    }
                    else
                    {
                        me.WorkValue       = me.Value.ToString(System.Globalization.CultureInfo.CurrentCulture);
                        me.txEntryBox.Text = me.Value.ToString(System.Globalization.CultureInfo.CurrentCulture);
                    }
                    me.SettingValues = false;
                }
            }
        }