Exemplo n.º 1
0
        /// <summary>
        /// Creates and starts an animation on the target element that binds either the X or Y axis of the source <see cref="ScrollViewer"/>
        /// </summary>
        /// <param name="scroller">The source <see cref="ScrollViewer"/> control to use</param>
        /// <param name="target">The target <see cref="UIElement"/> that will be animated</param>
        /// <param name="sourceAxis">The scrolling axis of the source <see cref="ScrollViewer"/></param>
        /// <param name="targetAxis">The optional scrolling axis of the target element, if <see langword="null"/> the source axis will be used</param>
        /// <param name="property">The target <see cref="Visual"/> property to animate.</param>
        /// <returns>An <see cref="ExpressionAnimation"/> instance that represents an already running animation.</returns>
        public static ExpressionAnimation StartExpressionAnimation(
            this ScrollViewer scroller,
            UIElement target,
            Axis sourceAxis,
            Axis targetAxis,
            VisualProperty property = VisualProperty.Translation)
        {
            CompositionPropertySet scrollSet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroller);

            ExpressionAnimation animation = scrollSet.Compositor.CreateExpressionAnimation($"{nameof(scroller)}.{nameof(UIElement.Translation)}.{sourceAxis}");

            animation.SetReferenceParameter(nameof(scroller), scrollSet);

            Visual visual = ElementCompositionPreview.GetElementVisual(target);

            switch (property)
            {
            case VisualProperty.Translation:
                ElementCompositionPreview.SetIsTranslationEnabled(target, true);
                visual.StartAnimation($"{nameof(Matrix4x4.Translation)}.{targetAxis}", animation);
                break;

            case VisualProperty.Offset:
                visual.StartAnimation($"{nameof(Visual.Offset)}.{targetAxis}", animation);
                break;

            default: throw new ArgumentException($"Invalid target property: {property}", nameof(property));
            }

            return(animation);
        }
        protected override Task Render(VisualProperty property, CodeGeneratorContext context)
        {
            var gen = (CodeMemberMethod)context.CodeScope.Peek();

            switch (property.Key)
            {
            case "template":
                CodeGeneration_Visuals.EnsureLayout(context, property.Value);
                var method = new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression("Output"),
                    "SetTemplate",
                    new CodeVariableReferenceExpression(CodeConstants.RequestVariableName),
                    new CodePrimitiveExpression(property.Value));
                gen.Statements.Add(method);
                break;

            case "background":
            case "title":
            case "subtitle":
                var propertyMethod = new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression("Output"),
                    "SetDataProperty",
                    new CodeVariableReferenceExpression(CodeConstants.RequestVariableName),
                    new CodePrimitiveExpression(property.Key.ToLower()),
                    new CodePrimitiveExpression(property.Value));
                gen.Statements.Add(propertyMethod);
                break;
            }
            return(Noop(context));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates and starts an animation on the target element that binds either the X or Y axis of the source <see cref="ScrollViewer"/>.
 /// </summary>
 /// <param name="scroller">The source <see cref="ScrollViewer"/> control to use.</param>
 /// <param name="target">The target <see cref="UIElement"/> that will be animated.</param>
 /// <param name="axis">The scrolling axis of the source <see cref="ScrollViewer"/>.</param>
 /// <param name="property">The target <see cref="Visual"/> property to animate.</param>
 /// <returns>An <see cref="ExpressionAnimation"/> instance that represents an already running animation.</returns>
 public static ExpressionAnimation StartExpressionAnimation(
     this ScrollViewer scroller,
     UIElement target,
     Axis axis,
     VisualProperty property = VisualProperty.Translation)
 {
     return(scroller.StartExpressionAnimation(target, axis, axis, property));
 }
        public InterpreterResult Interpret(string candidate, SkillFlowInterpretationContext context)
        {
            var keyvalue = candidate.Split(new[] { ':' }, 2).Select(s => s.Trim()).ToArray();

            if (keyvalue.Length < 2)
            {
                throw new InvalidSkillFlowDefinitionException($"Unable to interpret visual property {candidate}", context.LineNumber);
            }

            if (!_validProperties.Contains(keyvalue[0]) || !quoters.Contains(keyvalue[1][0]) || !quoters.Contains(keyvalue[1].Last()))
            {
                throw new InvalidSkillFlowDefinitionException($"Unable to interpret visual property {keyvalue[0]}", context.LineNumber);
            }

            var property = new VisualProperty(keyvalue[0], keyvalue[1].Substring(1, keyvalue[1].Length - 2));

            return(new InterpreterResult(property));
        }
 protected override async Task Render(VisualProperty story, TextGeneratorContext context)
 {
     await context.WriteLine($"{story.Key}: \'{story.Value}\'");
 }
Exemplo n.º 6
0
 set => SetValue(VisualProperty, value);
Exemplo n.º 7
0
 public virtual void AddProperty(VisualProperty property)
 {
     m_visualProperties.Add(property);
     property.Owner = this;
 }
 protected virtual Task Render(VisualProperty story, TContext context)
 {
     return(Noop(context));
 }