You generate the .cs with the .json, like :
LottieGen -Language CSharp -Public -WinUIVersion 3.0 -InputFile E:\Sources\WinUI3_Lottie\Assets\130153-santa-telegram-sticker.json
You Add : Microsoft.Graphics.Win2D package
You replace in the generated .cs :
IAnimatedVisual2
by
IAnimatedVisual
You replace :
result = (IGeometrySource2D)(object)CanvasGeometry.CreatePath(builder);
by
result = CanvasGeometry.CreatePath(builder);
and XAML with just a Button and the Lottie (change the main class) :
<!-- Copyright (c) Microsoft Corporation and Contributors. -->
<!-- Licensed under the MIT License. -->
<Window
x:Class="WinUI3_Lottie.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WinUI3_Lottie"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:animatedvisuals="using:AnimatedVisuals"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
<!--Copied from WinUI3 Gallery-->
<Border Width="400" Height="400"
BorderBrush="{ThemeResource ToolTipBorderThemeBrush}"
BorderThickness="5"
Background="LightGray"
Margin="0, 20, 0, 20">
<!-- AnimatedVisualPlayer -->
<AnimatedVisualPlayer x:Name="Player"
AutoPlay="False">
<AnimatedVisualPlayer.Source>
<!-- Codegen-ed Lottie animation source: /AnimatedVisuals/LottieLogo1.cs -->
<animatedvisuals:_130153_santa_telegram_sticker/>
</AnimatedVisualPlayer.Source>
<!-- Fallback since Lottie-Windows is only supported on OS version 17763 and above -->
<AnimatedVisualPlayer.FallbackContent>
<DataTemplate>
<Image Source="/Assets/130153-santa-telegram-sticker.gif"/>
</DataTemplate>
</AnimatedVisualPlayer.FallbackContent>
</AnimatedVisualPlayer>
</Border>
</StackPanel>
</Window>
Button click :
private void myButton_Click(object sender, RoutedEventArgs e)
{
//myButton.Content = "Clicked";
if (!Player.IsPlaying)
{
// Play the animation at the currently specified playback rate.
_ = Player.PlayAsync(fromProgress: 0, toProgress: 1, looped: false);
}
}