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

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

            if (!box.IsInternalPropertyChange)
            {
                throw new InvalidOperationException("ValueString property is readonly.");
            }
        }
Example #3
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);
            }
        }