-
Notifications
You must be signed in to change notification settings - Fork 193
Description
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!