/// <summary> /// Invokes this action. /// </summary> /// <param name="parameter"></param> protected override void Invoke(object parameter) { object currentValue = this.listener.Value; if (currentValue != null) { object newValue = ConverterHelper.ConvertToType(this.Value, currentValue.GetType()); if (this.Increment) { newValue = FluidBindProperty.Add(currentValue, newValue); } this.listener.Value = newValue; } else { this.listener.Value = this.Value; } }
internal static void AnimateTo(FrameworkElement target, string propertyName, object value, Duration duration, bool increment) { #endif if (!string.IsNullOrEmpty(propertyName) && target != null) { PropertyInfo property = target.GetType().GetProperty(propertyName); if (property == null) { throw new ArgumentException("Cannot find property " + propertyName + " on object " + target.GetType().Name); } if (!property.CanWrite) { throw new ArgumentException("Property is read-only " + propertyName + " on object " + target.GetType().Name); } object toValue = value; TypeConverter typeConverter = ConverterHelper.GetTypeConverter(property.PropertyType); Exception innerException = null; try { if (((typeConverter != null) && (value != null)) && typeConverter.CanConvertFrom(value.GetType())) { toValue = typeConverter.ConvertFrom(value); } object fromValue = property.GetValue(target, null); if (increment) { toValue = FluidBindProperty.Add(toValue, fromValue); } if (duration.HasTimeSpan) { Timeline timeline; if ((typeof(FrameworkElement).IsAssignableFrom(target.GetType()) && ((propertyName == "Width") || (propertyName == "Height"))) && double.IsNaN((double)fromValue)) { if (propertyName == "Width") { fromValue = target.ActualWidth; } else { fromValue = target.ActualHeight; } } Storyboard storyboard = new Storyboard(); if (typeof(double).IsAssignableFrom(property.PropertyType)) { DoubleAnimation animation = new DoubleAnimation(); animation.From = new double?((double)fromValue); animation.To = new double?((double)toValue); #if SILVERLIGHT animation.EasingFunction = ease; #endif timeline = animation; } else if (typeof(Color).IsAssignableFrom(property.PropertyType)) { ColorAnimation animation2 = new ColorAnimation(); animation2.From = new Color?((Color)fromValue); animation2.To = new Color?((Color)toValue); #if SILVERLIGHT animation2.EasingFunction = ease; #endif timeline = animation2; } else if (typeof(Point).IsAssignableFrom(property.PropertyType)) { PointAnimation animation3 = new PointAnimation(); animation3.From = new Point?((Point)fromValue); animation3.To = new Point?((Point)toValue); #if SILVERLIGHT animation3.EasingFunction = ease; #endif timeline = animation3; } else { ObjectAnimationUsingKeyFrames frames = new ObjectAnimationUsingKeyFrames(); DiscreteObjectKeyFrame frame = new DiscreteObjectKeyFrame(); frame.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0L)); frame.Value = fromValue; DiscreteObjectKeyFrame frame2 = new DiscreteObjectKeyFrame(); frame2.KeyTime = KeyTime.FromTimeSpan(duration.TimeSpan); frame2.Value = toValue; frames.KeyFrames.Add(frame); frames.KeyFrames.Add(frame2); timeline = frames; } timeline.Duration = duration; storyboard.Children.Add(timeline); Storyboard.SetTarget(storyboard, target); Storyboard.SetTargetProperty(storyboard, new PropertyPath(property.Name, new object[0])); storyboard.Begin(); } else { property.SetValue(target, toValue, new object[0]); } } catch (FormatException exception2) { innerException = exception2; } catch (ArgumentException exception3) { innerException = exception3; } catch (MethodAccessException exception4) { innerException = exception4; } if (innerException != null) { throw new ArgumentException(innerException.Message); } } }