You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WinUI 3中如何替代AnimatedVisualPlayer实现Lottie动画?

在WinUI 3中实现Lottie动画的替代方案

WinUI 3中没有直接对应UWP里AnimatedVisualPlayer的组件,但可以通过CommunityToolkit.WinUI.Lottie这个官方工具包来实现Lottie动画,该包是专门为WinUI 3适配的Lottie解决方案。

实现步骤:

  • 首先安装NuGet包:CommunityToolkit.WinUI.Lottie
  • 在XAML中直接使用LottieVisualPlayer控件,该控件已整合了动画播放的核心功能,无需嵌套额外的播放器组件。

XAML代码示例:

<Page
    x:Class="YourNamespace.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:lottie="using:CommunityToolkit.WinUI.Lottie">

    <Grid>
        <lottie:LottieVisualPlayer 
            Stretch="None"
            Source="ms-appx:///Assets/AnimatedImage.json"
            AutoPlay="True"
            RepeatMode="Loop" />
    </Grid>
</Page>

代码控制示例(C#):

如果需要通过代码手动控制动画状态,可以参考以下示例:

// 播放动画
myLottiePlayer.PlayAsync();

// 暂停动画
myLottiePlayer.Pause();

// 停止动画并重置到初始帧
myLottiePlayer.Stop();

// 设置自动播放
myLottiePlayer.AutoPlay = true;

内容的提问来源于stack exchange,提问作者Sumnoon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 00:19:54