/// <summary>
        /// Creates a new <see cref="AnimationKeyframeBase"/> instance from the specified keyframe definition.
        /// </summary>
        /// <param name="keyframeDefinition">The keyframe definition to instantiate.</param>
        /// <param name="keyframeValueType">The type of value being animated by the keyframe.</param>
        /// <returns>The <see cref="AnimationKeyframeBase"/> instance that was created.</returns>
        private AnimationKeyframeBase InstantiateStoryboardAnimationKeyframe(UvssStoryboardKeyframe keyframeDefinition, Type keyframeValueType)
        {
            var time = TimeSpan.FromMilliseconds(keyframeDefinition.Time);

            var easing = default(EasingFunction);

            if (!String.IsNullOrEmpty(keyframeDefinition.Easing))
            {
                standardEasingFunctions.TryGetValue(keyframeDefinition.Easing, out easing);
            }

            var valueDef = keyframeDefinition.Value;
            var value    = valueDef.IsEmpty ? null :
                           ObjectResolver.FromString(valueDef.Value, keyframeValueType, valueDef.Culture, true);

            var keyframeType     = typeof(AnimationKeyframe <>).MakeGenericType(keyframeValueType);
            var keyframeInstance = (value == null) ?
                                   (AnimationKeyframeBase)Activator.CreateInstance(keyframeType, time, easing) :
                                   (AnimationKeyframeBase)Activator.CreateInstance(keyframeType, time, value, easing);

            return(keyframeInstance);
        }
        /// <summary>
        /// Creates a new <see cref="AnimationKeyframeBase"/> instance based on the specified <see cref="UvssStoryboardKeyframe"/>.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="keyframeDefinition">The storyboard keyframe definition.</param>
        /// <param name="animatedType">The type of value which is being animated.</param>
        /// <returns>The reified storyboard animation keyframe.</returns>
        public static AnimationKeyframeBase ReifyStoryboardAnimationKeyframe(UltravioletContext uv, UvssStoryboardKeyframe keyframeDefinition, Type animatedType)
        {
            Contract.Require(keyframeDefinition, "keyframeDefinition");
            Contract.Require(animatedType, "animatedType");

            var keyframeType = typeof(AnimationKeyframe<>).MakeGenericType(animatedType);

            var time   = TimeSpan.FromMilliseconds(keyframeDefinition.Time);
            var easing = ParseEasingFunction(keyframeDefinition.Easing);
            var str    = keyframeDefinition.Value == null ? null : keyframeDefinition.Value.Trim();
            var value  = String.IsNullOrWhiteSpace(str) ? null : ObjectResolver.FromString(str, animatedType, true);

            var keyframe = (value == null) ?
                    (AnimationKeyframeBase)Activator.CreateInstance(keyframeType, time, easing) :
                    (AnimationKeyframeBase)Activator.CreateInstance(keyframeType, time, value, easing);

            return keyframe;
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new <see cref="AnimationKeyframeBase"/> instance from the specified keyframe definition.
        /// </summary>
        /// <param name="keyframeDefinition">The keyframe definition to instantiate.</param>
        /// <param name="keyframeValueType">The type of value being animated by the keyframe.</param>
        /// <returns>The <see cref="AnimationKeyframeBase"/> instance that was created.</returns>
        private AnimationKeyframeBase InstantiateStoryboardAnimationKeyframe(UvssStoryboardKeyframe keyframeDefinition, Type keyframeValueType)
        {
            var time = TimeSpan.FromMilliseconds(keyframeDefinition.Time);

            var easing = default(EasingFunction);
            if (!String.IsNullOrEmpty(keyframeDefinition.Easing))
                standardEasingFunctions.TryGetValue(keyframeDefinition.Easing, out easing);

            var valueDef = keyframeDefinition.Value;
            var value = valueDef.IsEmpty ? null :
                ObjectResolver.FromString(valueDef.Value, keyframeValueType, valueDef.Culture, true);

            var keyframeType = typeof(AnimationKeyframe<>).MakeGenericType(keyframeValueType);
            var keyframeInstance = (value == null) ?
                (AnimationKeyframeBase)Activator.CreateInstance(keyframeType, time, easing) :
                (AnimationKeyframeBase)Activator.CreateInstance(keyframeType, time, value, easing);

            return keyframeInstance;
        }