Skip to content

Commit ed98180

Browse files
committed
Add Lottie Island to WpfCalculator
1 parent b9cfdf1 commit ed98180

20 files changed

+7451
-2
lines changed

Samples/Islands/WpfCalculator/CalculatorDemo/CalculatorDemo.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<SubType>Code</SubType>
9898
</Compile>
9999
<Compile Include="App_Demo3.cs" />
100+
<Compile Include="LottieIslandScenario.cs" />
100101
<Compile Include="MainWindow.cs">
101102
<DependentUpon>MainWindow.xaml</DependentUpon>
102103
<SubType>Code</SubType>
@@ -141,6 +142,8 @@
141142
<!-- Demo4_Step2_AddIsland -->
142143
<ItemGroup>
143144
<ProjectReference Include="..\DrawingIslandCsProjection\DrawingIslandCsProjection.csproj" />
145+
<PackageReference Include="CommunityToolkit.WinAppSDK.LottieWinRT" Version="8.0.230819-rc-LottieIsland.7.g92a87e1883" />
146+
<PackageReference Include="CommunityToolkit.WinUI.Lottie" Version="8.0.230819-rc-LottieIsland.7.g92a87e1883" />
144147
</ItemGroup>
145148
<!-- -->
146149
<ItemGroup>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using Microsoft.UI.Composition;
3+
using CommunityToolkit.WinAppSDK.LottieIsland;
4+
using CommunityToolkit.WinAppSDK.LottieWinRT;
5+
6+
class LottieIslandScenario
7+
{
8+
public static LottieContentIsland CreateLottieIsland(Compositor compositor)
9+
{
10+
var lottieIsland = LottieContentIsland.Create(compositor);
11+
var lottieVisualSource = LottieVisualSourceWinRT.CreateFromString(
12+
"ms-appx:///Assets/LottieLogo1.json");
13+
14+
if (lottieVisualSource != null)
15+
{
16+
lottieVisualSource.AnimatedVisualInvalidated += (sender, args) =>
17+
{
18+
object? diagnostics = null;
19+
IAnimatedVisualFrameworkless? animatedVisual =
20+
lottieVisualSource.TryCreateAnimatedVisual(compositor, out diagnostics);
21+
22+
if (animatedVisual != null)
23+
{
24+
// This callback comes back on a different thread, so set the AnimatedVisual on
25+
// the UI thread
26+
compositor.DispatcherQueue.TryEnqueue(async () =>
27+
{
28+
lottieIsland.AnimatedVisual = animatedVisual;
29+
await lottieIsland.PlayAsync(0, 1, true);
30+
});
31+
}
32+
};
33+
}
34+
35+
return lottieIsland;
36+
}
37+
}

Samples/Islands/WpfCalculator/CalculatorDemo/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<MenuItem Header="File">
2929
<!-- Demo4_Step2_AddIsland -->
3030
<MenuItem Name="CreateDrawingIslandMenuItem" Click="CreateDrawingIslandMenuItem_Click" Header="Create DrawingIsland" />
31+
<MenuItem Name="CreateLottieIslandMenuItem" Click="CreateLottieIslandMenuItem_Click" Header="Create LottieIsland" />
3132
<!-- -->
3233
<MenuItem Click="OnMenuExit" Header="Exit" />
3334
</MenuItem>

Samples/Islands/WpfCalculator/CalculatorDemo/MainWindow_Demo4.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// // Copyright (c) Microsoft. All rights reserved.
22
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using CommunityToolkit.WinAppSDK.LottieIsland;
45
using System.Windows;
56

67
#if true // Demo3_Step2_AddCompact
@@ -20,6 +21,19 @@ private void CreateDrawingIslandMenuItem_Click(object sender, RoutedEventArgs e)
2021

2122
wpfIslandHost.DesktopChildSiteBridge.Connect(drawingIsland.Island);
2223
}
24+
25+
private void CreateLottieIslandMenuItem_Click(object sender, RoutedEventArgs e)
26+
{
27+
var wpfIslandHost = new WpfIslandHost(_compositor);
28+
_lottieContentIsland = LottieIslandScenario.CreateLottieIsland(_compositor);
29+
30+
// After this, the WpfIslandHost will be live, and the DesktopChildSiteBridge will be available.
31+
DisplayAreaBorder.Child = wpfIslandHost;
32+
33+
wpfIslandHost.DesktopChildSiteBridge.Connect(_lottieContentIsland.Island);
34+
}
35+
36+
LottieContentIsland _lottieContentIsland;
2337
}
2438
}
2539

0 commit comments

Comments
 (0)