Skip to content

Creating a CompositionPath in WinUI #141

Description

@jennHarper

I want to create a wave animation in WinUI.
I have a PathGeometry that implements a Bezier curve but I can't seem to convert it to the CompositionPath that I need.

PathGeometry animationPath = new PathGeometry();
PathFigure pFigure = new PathFigure();
pFigure.StartPoint = new Point(00, 300);
PolyBezierSegment pBezierSegment = new PolyBezierSegment();
pBezierSegment.Points.Add(new Point(600, 300 - 820));
pBezierSegment.Points.Add(new Point(1200, 300 + 820));
pBezierSegment.Points.Add(new Point(1800, 300));
pFigure.Segments.Add(pBezierSegment);
animationPath.Figures.Add(pFigure);

Online searches have suggested the following:
CompositionEasingFunction linearEasingFunction = compositor.CreateLinearEasingFunction();

PathKeyFrameAnimation wave = compositor.CreatePathKeyFrameAnimation();

CanvasGeometry result;
using (var builder = new CanvasPathBuilder(null))
{
builder.BeginFigure(new Vector2(-13.6639996F, -0.144999996F));
builder.AddLine(new Vector2(375.663002F, 400.289999992F));
builder.EndFigure(CanvasFigureLoop.Open);
result = CanvasGeometry.CreatePath(builder);
}

CompositionPath p = new CompositionPath((IGeometrySource2D)(object)result);

wave.InsertKeyFrame(1.0f, p, linearEasingFunction);

wave.Duration = TimeSpan.FromSeconds(10);
visual.StartAnimation("Offset", wave);

However, I seem to need to install the Win2D.uwp package to get CanvasGeometry, but then on run I get errors. Is there anything native to WinUI, not UWP, that I can use to create a path. I just haven't seen anything other than CanvasGeometry that implements IGeometrySource2D.

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions