Reworked animations

This commit is contained in:
ClemensFischer 2024-05-21 22:05:01 +02:00
parent 12b33c5376
commit 8708c7ffe6
9 changed files with 159 additions and 85 deletions

View file

@ -0,0 +1,59 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Threading.Tasks;
using System;
using Avalonia.Controls;
using Avalonia.Animation;
using Avalonia.Styling;
using System.Xml.Linq;
namespace MapControl
{
public static class OpacityHelper
{
public static Task FadeIn(Control element)
{
var animation = new Animation
{
Duration = MapBase.ImageFadeDuration,
Children =
{
new KeyFrame
{
KeyTime = TimeSpan.Zero,
Setters = { new Setter(Visual.OpacityProperty, 0d) }
},
new KeyFrame
{
KeyTime = MapBase.ImageFadeDuration,
Setters = { new Setter(Visual.OpacityProperty, 1d) }
}
}
};
return animation.RunAsync(element);
}
public static async Task SwapOpacities(Control topElement, Control bottomElement)
{
var animation = new Animation
{
Duration = MapBase.ImageFadeDuration,
Children =
{
new KeyFrame
{
KeyTime = MapBase.ImageFadeDuration,
Setters = { new Setter(Visual.OpacityProperty, 1d) }
}
}
};
await animation.RunAsync(topElement);
bottomElement.Opacity = 0d;
}
}
}

View file

@ -2,35 +2,13 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Animation;
using Avalonia.Styling;
using System;
namespace MapControl
{
public partial class Tile
{
private void AnimateImageOpacity()
{
var animation = new Animation
{
Duration = MapBase.ImageFadeDuration,
Children =
{
new KeyFrame
{
KeyTime = TimeSpan.Zero,
Setters = { new Setter(Visual.OpacityProperty, 0d) }
},
new KeyFrame
{
KeyTime = MapBase.ImageFadeDuration,
Setters = { new Setter(Visual.OpacityProperty, 1d) }
}
}
};
_ = animation.RunAsync(Image);
_ = OpacityHelper.FadeIn(Image);
}
}
}