/// <summary> /// Creates a new <see cref="StoryboardTarget"/> instance from the specified target definition. /// </summary> /// <param name="targetDefinition">The storyboard target definition to instantiate.</param> /// <returns>The <see cref="StoryboardTarget"/> instance that was created.</returns> private StoryboardTarget InstantiateStoryboardTarget(UvssStoryboardTarget targetDefinition) { var target = new StoryboardTarget(targetDefinition.Selector); foreach (var animationDefinition in targetDefinition.Animations) { var animatedPropertyName = animationDefinition.AnimatedProperty; var animatedPropertyType = ResolvePropertyTypeFromFilter(Ultraviolet, targetDefinition.Filter, ref animatedPropertyName); var navigationExpression = default(NavigationExpression?); var navigationExpressionDef = animationDefinition.NavigationExpression; if (navigationExpressionDef != null) { animatedPropertyType = ResolvePropertyTypeFromFilter(Ultraviolet, new[] { navigationExpressionDef.NavigationPropertyType }, ref animatedPropertyName); navigationExpression = NavigationExpression.FromUvssNavigationExpression(Ultraviolet, navigationExpressionDef); } var animationKey = new StoryboardTargetAnimationKey(new DependencyName(animatedPropertyName), navigationExpression); var animation = InstantiateStoryboardAnimation(animationDefinition, animatedPropertyType); if (animation != null) { target.Animations.Add(animationKey, animation); } } return(target); }
/// <summary> /// Creates a new <see cref="StoryboardTarget"/> instance based on the specified <see cref="UvssStoryboardTarget"/>. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="targetDefinition">The storyboard target definition.</param> /// <returns>The reified storyboard target.</returns> public static StoryboardTarget ReifyStoryboardTarget(UltravioletContext uv, UvssStoryboardTarget targetDefinition) { Contract.Require(targetDefinition, "targetDefinition"); var target = new StoryboardTarget(targetDefinition.Selector); foreach (var animationDefinition in targetDefinition.Animations) { var animationKey = default(StoryboardTargetAnimationKey); var animation = ReifyStoryboardAnimation(uv, targetDefinition, animationDefinition, out animationKey); if (animation != null) { target.Animations.Add(animationKey, animation); } } return target; }
/// <summary> /// Creates a new <see cref="AnimationBase"/> instance based on the specified <see cref="UvssStoryboardAnimation"/>. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="targetDefinition">The type filter on the storyboard target.</param> /// <param name="animationDefinition">The storyboard animation definition.</param> /// <param name="animationKey">The name of the dependency property which is being animated.</param> /// <returns>The reified storyboard animation.</returns> public static AnimationBase ReifyStoryboardAnimation(UltravioletContext uv, UvssStoryboardTarget targetDefinition, UvssStoryboardAnimation animationDefinition, out StoryboardTargetAnimationKey animationKey) { Contract.Require(targetDefinition, "targetDefinition"); Contract.Require(animationDefinition, "animationDefinition"); var propertyName = animationDefinition.AnimatedProperty; var propertyType = GetDependencyPropertyType(uv, targetDefinition.Filter, ref propertyName); var navigationExpression = default(NavigationExpression?); var navigationExpressionDef = animationDefinition.NavigationExpression; if (navigationExpressionDef != null) { propertyType = GetDependencyPropertyType(uv, new[] { navigationExpressionDef.NavigationPropertyType }, ref propertyName); navigationExpression = NavigationExpression.FromUvssNavigationExpression(uv, navigationExpressionDef); } animationKey = new StoryboardTargetAnimationKey(new UvmlName(propertyName), navigationExpression); if (propertyType == null) return null; var animationType = GetAnimationType(propertyType); if (animationType == null) return null; var animation = (AnimationBase)Activator.CreateInstance(animationType); foreach (var keyframeDefinition in animationDefinition.Keyframes) { var keyframe = ReifyStoryboardAnimationKeyframe(uv, keyframeDefinition, propertyType); animation.AddKeyframe(keyframe); } return animation; }
/// <summary> /// Creates a new <see cref="StoryboardTarget"/> instance from the specified target definition. /// </summary> /// <param name="targetDefinition">The storyboard target definition to instantiate.</param> /// <returns>The <see cref="StoryboardTarget"/> instance that was created.</returns> private StoryboardTarget InstantiateStoryboardTarget(UvssStoryboardTarget targetDefinition) { var target = new StoryboardTarget(targetDefinition.Selector); foreach (var animationDefinition in targetDefinition.Animations) { var animatedPropertyName = animationDefinition.AnimatedProperty; var animatedPropertyType = ResolvePropertyTypeFromFilter(Ultraviolet, targetDefinition.Filter, ref animatedPropertyName); var navigationExpression = default(NavigationExpression?); var navigationExpressionDef = animationDefinition.NavigationExpression; if (navigationExpressionDef != null) { animatedPropertyType = ResolvePropertyTypeFromFilter(Ultraviolet, new[] { navigationExpressionDef.NavigationPropertyType }, ref animatedPropertyName); navigationExpression = NavigationExpression.FromUvssNavigationExpression(Ultraviolet, navigationExpressionDef); } var animationKey = new StoryboardTargetAnimationKey(new DependencyName(animatedPropertyName), navigationExpression); var animation = InstantiateStoryboardAnimation(animationDefinition, animatedPropertyType); if (animation != null) { target.Animations.Add(animationKey, animation); } } return target; }