예제 #1
0
        internal static RadSize GetSizeFromStyle(Style style)
        {
            double width  = 0;
            double height = 0;
            double value;

            foreach (Setter setter in style.Setters)
            {
                if (setter.Property == FrameworkElement.WidthProperty ||
                    setter.Property == FrameworkElement.MinWidthProperty)
                {
                    if (NumericConverter.TryConvertToDouble(setter.Value, out value))
                    {
                        width = value;
                    }
                }
                else if (setter.Property == FrameworkElement.HeightProperty ||
                         setter.Property == FrameworkElement.MinHeightProperty)
                {
                    if (NumericConverter.TryConvertToDouble(setter.Value, out value))
                    {
                        height = value;
                    }
                }
            }

            return(new RadSize(width, height));
        }
예제 #2
0
        protected override void InitializeBinding(DataPointBindingEntry binding)
        {
            ScatterDataPoint dataPoint = binding.DataPoint as ScatterDataPoint;

            if (this.xValueBinding != null)
            {
                object xValue = this.xValueBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(xValue, out doubleValue))
                {
                    dataPoint.XValue = doubleValue;
                }
            }

            if (this.yValueBinding != null)
            {
                object yValue = this.yValueBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(yValue, out doubleValue))
                {
                    dataPoint.YValue = doubleValue;
                }
            }

            base.InitializeBinding(binding);
        }
예제 #3
0
        protected override void InitializeBinding(DataPointBindingEntry binding)
        {
            PolarDataPoint dataPoint = binding.DataPoint as PolarDataPoint;

            if (this.valueBinding != null)
            {
                object value = this.valueBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(value, out doubleValue))
                {
                    dataPoint.Value = doubleValue;
                }
            }

            if (this.angleBinding != null)
            {
                object angle = this.angleBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(angle, out doubleValue))
                {
                    dataPoint.Angle = doubleValue;
                }
            }

            base.InitializeBinding(binding);
        }
예제 #4
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);
            }
        }
예제 #5
0
        /// <summary>
        /// Encapsulates the core filter logic exposed by the descriptor. Allows inheritors to provide their own custom filtering logic.
        /// </summary>
        /// <param name="itemValue">The property value, as defined by the <see cref="P:PropertyName" /> property.</param>
        /// <returns>
        /// True if the filter is passed and the associated item should be displayed, false otherwise.
        /// </returns>
        protected override bool PassesFilterOverride(object itemValue)
        {
            if (itemValue == null || this.Value == null)
            {
                return(itemValue == this.Value);
            }

            if (this.convertedValue == null)
            {
                this.TryConvertValue();
            }

            if (!this.convertedValue.HasValue)
            {
                return(false);
            }

            double itemDouble;

            if (!NumericConverter.TryConvertToDouble(itemValue, out itemDouble, CultureInfo.InvariantCulture, true))
            {
                return(false);
            }

            bool passes = true;

            switch (this.numericalOperator)
            {
            case NumericalOperator.EqualsTo:
                passes = this.convertedValue.Value == itemDouble;
                break;

            case NumericalOperator.DoesNotEqualTo:
                passes = this.convertedValue.Value != itemDouble;
                break;

            case NumericalOperator.IsGreaterThan:
                passes = itemDouble > this.convertedValue.Value;
                break;

            case NumericalOperator.IsGreaterThanOrEqualTo:
                passes = itemDouble >= this.convertedValue.Value;
                break;

            case NumericalOperator.IsLessThan:
                passes = itemDouble < this.convertedValue.Value;
                break;

            case NumericalOperator.IsLessThanOrEqualTo:
                passes = itemDouble <= this.convertedValue.Value;
                break;
            }

            return(passes);
        }
예제 #6
0
        protected override void InitializeBinding(DataPointBindingEntry binding)
        {
            if (this.valueBinding != null)
            {
                object value = this.valueBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(value, out doubleValue))
                {
                    (binding.DataPoint as SingleValueDataPoint).Value = doubleValue;
                }
            }

            base.InitializeBinding(binding);
        }
예제 #7
0
        protected override void InitializeBinding(DataPointBindingEntry binding)
        {
            OhlcDataPoint dataPoint = binding.DataPoint as OhlcDataPoint;

            if (this.highBinding != null)
            {
                object value = this.highBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(value, out doubleValue))
                {
                    dataPoint.High = doubleValue;
                }
            }

            if (this.lowBinding != null)
            {
                object value = this.lowBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(value, out doubleValue))
                {
                    dataPoint.Low = doubleValue;
                }
            }

            if (this.openBinding != null)
            {
                object value = this.openBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(value, out doubleValue))
                {
                    dataPoint.Open = doubleValue;
                }
            }

            if (this.closeBinding != null)
            {
                object value = this.closeBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(value, out doubleValue))
                {
                    dataPoint.Close = doubleValue;
                }
            }

            base.InitializeBinding(binding);
        }
예제 #8
0
        protected DataPoint GenerateDataPoint(object dataItem, int index)
        {
            DataPoint point = this.CreateDataPoint();

            if (dataItem == null)
            {
                return(point);
            }

            double value;

            if (NumericConverter.TryConvertToDouble(dataItem, out value))
            {
                this.ProcessDouble(point, value);
            }
            else if (dataItem is double[])
            {
                this.ProcessDoubleArray(point, (double[])dataItem);
            }
            else if (dataItem is double?[])
예제 #9
0
        protected override void InitializeBinding(DataPointBindingEntry binding)
        {
            bool highIsValidNumber = true;
            bool lowIsValidNumber  = true;

            RangeDataPoint rangeDataPoint = (RangeDataPoint)binding.DataPoint;

            if (this.highBinding != null)
            {
                object value = this.highBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(value, out doubleValue))
                {
                    rangeDataPoint.High = doubleValue;
                }
                else
                {
                    rangeDataPoint.High = 0d;
                    highIsValidNumber   = false;
                }
            }

            if (this.lowBinding != null)
            {
                object value = this.lowBinding.GetValue(binding.DataItem);
                double doubleValue;
                if (NumericConverter.TryConvertToDouble(value, out doubleValue))
                {
                    rangeDataPoint.Low = doubleValue;
                }
                else
                {
                    rangeDataPoint.Low = 0d;
                    lowIsValidNumber   = false;
                }
            }

            rangeDataPoint.isEmpty = !lowIsValidNumber && !highIsValidNumber;

            base.InitializeBinding(binding);
        }
예제 #10
0
        private void TryConvertValue()
        {
            if (this.Value == null)
            {
                return;
            }

            double value;

            // try parse the value from string first - XAML support
            if (this.Value is string)
            {
                if (double.TryParse((string)this.Value, out value))
                {
                    this.convertedValue = value;
                }
            }
            else if (NumericConverter.TryConvertToDouble(this.Value, out value, CultureInfo.InvariantCulture, true))
            {
                this.convertedValue = value;
            }
        }
예제 #11
0
        private void UpdateActualRange(IEnumerable <IMapShape> shapes, out bool isAttributeValid)
        {
            this.actualRange         = new ValueRange <double>();
            this.actualRange.minimum = double.PositiveInfinity;

            isAttributeValid = false;

            object value;
            double doubleValue;

            foreach (var shape in shapes)
            {
                value       = shape.GetAttribute(this.attributeNameCache);
                doubleValue = double.NegativeInfinity;

                if (value != null)
                {
                    isAttributeValid = true;
                    if (!NumericConverter.TryConvertToDouble(value, out doubleValue))
                    {
                        throw new ArgumentException("Expected numeric value for attribute " + this.attributeNameCache);
                    }

                    if (doubleValue > this.actualRange.maximum)
                    {
                        this.actualRange.maximum = doubleValue;
                    }
                    if (doubleValue < this.actualRange.minimum)
                    {
                        this.actualRange.minimum = doubleValue;
                    }
                }

                // TODO: We support null values to keep the doubleValues list indexes synchronized
                this.doubleValues.Add(doubleValue);
            }
        }