Fade animations

This commit is contained in:
ClemensFischer 2025-01-05 10:31:15 +01:00
parent b9a34fd5e4
commit 4c669f4df0
7 changed files with 45 additions and 39 deletions

View file

@ -17,28 +17,29 @@ namespace MapControl
{
public static void FadeOver(Image topImage, Image bottomImage)
{
var topImageAnimation = new DoubleAnimation
var fadeInAnimation = new DoubleAnimation
{
To = 1d,
Duration = MapBase.ImageFadeDuration
};
var bottomImageAnimation = new DoubleAnimation
var fadeOutAnimation = new DoubleAnimation
{
To = 0d,
BeginTime = MapBase.ImageFadeDuration,
Duration = TimeSpan.Zero
Duration = TimeSpan.Zero,
FillBehavior = FillBehavior.Stop
};
Storyboard.SetTargetProperty(topImageAnimation, nameof(Opacity));
Storyboard.SetTarget(topImageAnimation, topImage);
Storyboard.SetTargetProperty(fadeInAnimation, nameof(Opacity));
Storyboard.SetTarget(fadeInAnimation, topImage);
Storyboard.SetTargetProperty(bottomImageAnimation, nameof(Opacity));
Storyboard.SetTarget(bottomImageAnimation, bottomImage);
Storyboard.SetTargetProperty(fadeOutAnimation, nameof(Opacity));
Storyboard.SetTarget(fadeOutAnimation, bottomImage);
var storyboard = new Storyboard();
storyboard.Children.Add(topImageAnimation);
storyboard.Children.Add(bottomImageAnimation);
storyboard.Children.Add(fadeInAnimation);
storyboard.Children.Add(fadeOutAnimation);
storyboard.Begin();
}
}

View file

@ -16,24 +16,24 @@ namespace MapControl
{
public partial class Tile
{
private void BeginOpacityAnimation()
private void BeginFadeInAnimation()
{
var animation = new DoubleAnimation
var fadeInAnimation = new DoubleAnimation
{
From = 0d,
Duration = MapBase.ImageFadeDuration,
FillBehavior = FillBehavior.Stop
};
Storyboard.SetTargetProperty(animation, nameof(UIElement.Opacity));
Storyboard.SetTarget(animation, Image);
Storyboard.SetTargetProperty(fadeInAnimation, nameof(UIElement.Opacity));
Storyboard.SetTarget(fadeInAnimation, Image);
var storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Children.Add(fadeInAnimation);
storyboard.Begin();
}
private void AnimateImageOpacity()
private void FadeIn()
{
if (Image.Source is BitmapImage bitmap && bitmap.UriSource != null)
{
@ -42,7 +42,7 @@ namespace MapControl
}
else
{
BeginOpacityAnimation();
BeginFadeInAnimation();
}
}
@ -53,7 +53,7 @@ namespace MapControl
bitmap.ImageOpened -= BitmapImageOpened;
bitmap.ImageFailed -= BitmapImageFailed;
BeginOpacityAnimation();
BeginFadeInAnimation();
}
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)