Beispiel #1
0
        private static void OnValueFormatSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RadNumericBox box = d as RadNumericBox;

            if (box.IsTemplateApplied)
            {
                box.UpdateTextBoxText();
            }
        }
Beispiel #2
0
        private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RadNumericBox numericBox = d as RadNumericBox;

            if (numericBox == null || numericBox.IsInternalPropertyChange)
            {
                return;
            }

            numericBox.updatingValue = true;

            double?oldValue       = numericBox.valueCache;
            double?newDoubleValue = null;

            if (e.NewValue != null)
            {
                double doubleValue;
                if (!NumericConverter.TryConvertToDouble(e.NewValue, out doubleValue))
                {
                    throw new ArgumentException("The object of type " + e.NewValue.GetType() + " may not be converted to a numerical value.");
                }

                RangeControlBase.VerifyValidDoubleValue(doubleValue);
                newDoubleValue = doubleValue;
            }

            if (numericBox.IsTemplateApplied)
            {
                var coercedValue = numericBox.CoerceValue(newDoubleValue);
                if (coercedValue.HasValue)
                {
                    newDoubleValue = coercedValue.Value;
                }
            }

            numericBox.valueCache = newDoubleValue;

            numericBox.updatingValue = false;

            if (oldValue != numericBox.Value)
            {
                if (numericBox.TextBox != null && numericBox.TextBox.FocusState == FocusState.Unfocused)
                {
                    numericBox.UpdateTextBoxText();
                }

                numericBox.OnValueChanged();
            }

            RadNumericBoxAutomationPeer peer = FrameworkElementAutomationPeer.FromElement(numericBox) as RadNumericBoxAutomationPeer;

            if (peer != null && oldValue != null && newDoubleValue != null)
            {
                peer.RaiseValuePropertyChangedEvent(oldValue, newDoubleValue);
            }
        }