public static TryConvert ( object value, DateTime &dateTimeValue ) : bool | ||
value | object | The value to convert. |
dateTimeValue | DateTime | The double value. |
Résultat | bool |
/// <summary> /// Called when the ActualIndependentValue property changes. /// </summary> /// <param name="oldValue">The value to be replaced.</param> /// <param name="newValue">The new value.</param> protected virtual void OnActualIndependentValuePropertyChanged(object oldValue, object newValue) { double coercedValue = 0.0; if (!(newValue is double) && ValueHelper.TryConvert(newValue, out coercedValue)) { _isCoercingActualIndependentValue = true; _oldActualIndependentValueBeforeCoercion = oldValue; } if (!_isCoercingActualIndependentValue) { if (_oldActualIndependentValueBeforeCoercion != null) { oldValue = _oldActualIndependentValueBeforeCoercion; _oldActualIndependentValueBeforeCoercion = null; } RoutedPropertyChangedEventHandler <object> handler = this.ActualIndependentValueChanged; if (handler != null) { handler(this, new RoutedPropertyChangedEventArgs <object>(oldValue, newValue)); } } if (_isCoercingActualIndependentValue) { _isCoercingActualIndependentValue = false; this.ActualIndependentValue = coercedValue; } }
/// <summary> /// Called when the IndependentValue property changes. /// </summary> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> protected virtual void OnIndependentValuePropertyChanged(object oldValue, object newValue) { SetFormattedProperty(FormattedIndependentValueProperty, IndependentValueStringFormat, newValue); RoutedPropertyChangedEventHandler <object> handler = this.IndependentValueChanged; if (handler != null) { handler(this, new RoutedPropertyChangedEventArgs <object>(oldValue, newValue)); } if (this.State == (int)DataPointState.Created) { // Prefer setting the value as a double... double coercedNewValue; if (ValueHelper.TryConvert(newValue, out coercedNewValue)) { ActualIndependentValue = coercedNewValue; } else { // ... but fall back otherwise ActualIndependentValue = newValue; } } }
/// <summary> /// Called when the DependentValue property changes. /// </summary> /// <param name="oldValue">The value to be replaced.</param> /// <param name="newValue">The new value.</param> protected virtual void OnDependentValuePropertyChanged(IComparable oldValue, IComparable newValue) { SetFormattedProperty(FormattedDependentValueProperty, DependentValueStringFormat, newValue); RoutedPropertyChangedEventHandler <IComparable> handler = this.DependentValueChanged; if (handler != null) { handler(this, new RoutedPropertyChangedEventArgs <IComparable>(oldValue, newValue)); } if (this.State == (int)DataPointState.Created) { // Prefer setting the value as a double... double coercedNewValue; if (ValueHelper.TryConvert(newValue, out coercedNewValue)) { ActualDependentValue = coercedNewValue; } else { // ... but fall back otherwise ActualDependentValue = (double /*IComparable*/)newValue; } } }
/// <summary> /// Acquires an independent axis suitable for use with the data values of the series. /// </summary> /// <returns>Axis instance.</returns> protected override IAxis AcquireIndependentAxis() { IAxis independentAxis = SeriesHost.Axes .Where(a => (a.Orientation == AxisOrientation.X) && ((a is IRangeAxis) || (a is ICategoryAxis)) && DataItems.Any() && (a.CanPlot(DataItems.First().ActualIndependentValue))) .FirstOrDefault(); if (null == independentAxis) { object probeValue = DataItems.Any() ? DataItems.First().ActualIndependentValue : null; double convertedDouble; DateTime convertedDateTime; if ((null != probeValue) && ValueHelper.TryConvert(probeValue, out convertedDouble)) { independentAxis = new LinearAxis(); } else if ((null != probeValue) && ValueHelper.TryConvert(probeValue, out convertedDateTime)) { independentAxis = new DateTimeAxis(); } else { independentAxis = new CategoryAxis(); } independentAxis.Orientation = AxisOrientation.X; } return(independentAxis); }
/// <summary> /// Creates the correct range axis based on the data. /// </summary> /// <param name="value">The value to evaluate to determine which type of /// axis to create.</param> /// <returns>The range axis appropriate that can plot the provided /// value.</returns> protected static IRangeAxis CreateRangeAxisFromData(object value) { double doubleValue; DateTime dateTime; if (ValueHelper.TryConvert(value, out doubleValue)) { return(new LinearAxis()); } else if (ValueHelper.TryConvert(value, out dateTime)) { return(new DateTimeAxis()); } else { return(null); } }
private static Storyboard CreateStoryboard( FrameworkElement target, DependencyProperty animatingDependencyProperty, string propertyPath, ref object toValue, TimeSpan durationTimeSpan, EasingFunctionBase easingFunction) { object fromValue = target.GetValue(animatingDependencyProperty); double fromDoubleValue; double toDoubleValue; DateTime fromDateTime; DateTime toDateTime; Storyboard storyBoard = new Storyboard(); Storyboard.SetTarget(storyBoard, target); Storyboard.SetTargetProperty(storyBoard, propertyPath); if ((fromValue != null && toValue != null)) { if (ValueHelper.TryConvert(fromValue, out fromDoubleValue) && ValueHelper.TryConvert(toValue, out toDoubleValue)) { DoubleAnimation doubleAnimation = new DoubleAnimation(); doubleAnimation.EnableDependentAnimation = true; #if !NO_EASING_FUNCTIONS doubleAnimation.EasingFunction = easingFunction; #endif doubleAnimation.Duration = durationTimeSpan; doubleAnimation.To = ValueHelper.ToDouble(toValue); toValue = doubleAnimation.To; storyBoard.Children.Add(doubleAnimation); } else if (ValueHelper.TryConvert(fromValue, out fromDateTime) && ValueHelper.TryConvert(toValue, out toDateTime)) { ObjectAnimationUsingKeyFrames keyFrameAnimation = new ObjectAnimationUsingKeyFrames(); keyFrameAnimation.EnableDependentAnimation = true; keyFrameAnimation.Duration = durationTimeSpan; long intervals = (long)(durationTimeSpan.TotalSeconds * KeyFramesPerSecond); if (intervals < 2L) { intervals = 2L; } IEnumerable <TimeSpan> timeSpanIntervals = ValueHelper.GetTimeSpanIntervalsInclusive(durationTimeSpan, intervals); IEnumerable <DateTime> dateTimeIntervals = ValueHelper.GetDateTimesBetweenInclusive(fromDateTime, toDateTime, intervals); IEnumerable <DiscreteObjectKeyFrame> keyFrames = EnumerableFunctions.Zip( dateTimeIntervals, timeSpanIntervals, (dateTime, timeSpan) => new DiscreteObjectKeyFrame() { Value = dateTime, KeyTime = timeSpan }); foreach (DiscreteObjectKeyFrame keyFrame in keyFrames) { keyFrameAnimation.KeyFrames.Add(keyFrame); toValue = keyFrame.Value; } storyBoard.Children.Add(keyFrameAnimation); } } if (storyBoard.Children.Count == 0) { ObjectAnimationUsingKeyFrames keyFrameAnimation = new ObjectAnimationUsingKeyFrames(); keyFrameAnimation.EnableDependentAnimation = true; DiscreteObjectKeyFrame endFrame = new DiscreteObjectKeyFrame() { Value = toValue, KeyTime = new TimeSpan(0, 0, 0) }; keyFrameAnimation.KeyFrames.Add(endFrame); storyBoard.Children.Add(keyFrameAnimation); } return(storyBoard); }
/// <summary> /// Returns a value indicating whether a value can plot. /// </summary> /// <param name="value">The value to plot.</param> /// <returns>A value indicating whether a value can plot.</returns> public override bool CanPlot(object value) { DateTime val; return(ValueHelper.TryConvert(value, out val)); }