XAML-Map-Control/MapControl/WinUI/OpacityHelper.WinUI.cs
ClemensFischer 560f44a139 Copyright
2025-01-01 18:57:55 +01:00

48 lines
1.3 KiB
C#

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// Copyright © Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Threading.Tasks;
#if UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Animation;
#else
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media.Animation;
#endif
namespace MapControl
{
public static class OpacityHelper
{
public static void BeginOpacityAnimation(DependencyObject obj, DoubleAnimation animation)
{
Storyboard.SetTargetProperty(animation, nameof(UIElement.Opacity));
Storyboard.SetTarget(animation, obj);
var storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Begin();
}
public static Task SwapOpacitiesAsync(UIElement topElement, UIElement bottomElement)
{
BeginOpacityAnimation(topElement, new DoubleAnimation
{
To = 1d,
Duration = MapBase.ImageFadeDuration
});
BeginOpacityAnimation(bottomElement, new DoubleAnimation
{
To = 0d,
BeginTime = MapBase.ImageFadeDuration,
Duration = TimeSpan.Zero
});
return Task.CompletedTask;
}
}
}