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

@ -10,7 +10,7 @@ namespace MapControl
{
public static void FadeOver(Image topImage, Image bottomImage)
{
var animation = new Animation
var fadeInAnimation = new Animation
{
FillMode = FillMode.Forward,
Duration = MapBase.ImageFadeDuration,
@ -24,7 +24,7 @@ namespace MapControl
}
};
_ = animation.RunAsync(topImage).ContinueWith(
_ = fadeInAnimation.RunAsync(topImage).ContinueWith(
_ => bottomImage.Opacity = 0d,
TaskScheduler.FromCurrentSynchronizationContext());
}

View file

@ -8,9 +8,9 @@ namespace MapControl
{
public partial class Tile
{
private void AnimateImageOpacity()
private void FadeIn()
{
var animation = new Animation
var fadeInAnimation = new Animation
{
Duration = MapBase.ImageFadeDuration,
Children =
@ -28,7 +28,7 @@ namespace MapControl
}
};
_ = animation.RunAsync(Image);
_ = fadeInAnimation.RunAsync(Image);
}
}
}

View file

@ -43,7 +43,7 @@ namespace MapControl
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
{
AnimateImageOpacity();
FadeIn();
}
}
}

View file

@ -12,18 +12,22 @@ namespace MapControl
{
public static void FadeOver(Image topImage, Image bottomImage)
{
topImage.BeginAnimation(OpacityProperty, new DoubleAnimation
var fadeInAnimation = new DoubleAnimation
{
To = 1d,
Duration = MapBase.ImageFadeDuration
});
};
bottomImage.BeginAnimation(OpacityProperty, new DoubleAnimation
var fadeOutAnimation = new DoubleAnimation
{
To = 0d,
BeginTime = MapBase.ImageFadeDuration,
Duration = TimeSpan.Zero
});
Duration = TimeSpan.Zero,
FillBehavior = FillBehavior.Stop
};
topImage.BeginAnimation(OpacityProperty, fadeInAnimation);
bottomImage.BeginAnimation(OpacityProperty, fadeOutAnimation);
}
}
}

View file

@ -13,18 +13,19 @@ namespace MapControl
{
public partial class Tile
{
private void BeginOpacityAnimation()
private void BeginFadeInAnimation()
{
Image.BeginAnimation(UIElement.OpacityProperty,
new DoubleAnimation
{
From = 0d,
Duration = MapBase.ImageFadeDuration,
FillBehavior = FillBehavior.Stop
});
var fadeInAnimation = new DoubleAnimation
{
From = 0d,
Duration = MapBase.ImageFadeDuration,
FillBehavior = FillBehavior.Stop
};
Image.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
}
private void AnimateImageOpacity()
private void FadeIn()
{
if (Image.Source is BitmapSource bitmap && bitmap.IsDownloading && !bitmap.IsFrozen)
{
@ -33,7 +34,7 @@ namespace MapControl
}
else
{
BeginOpacityAnimation();
BeginFadeInAnimation();
}
}
@ -44,7 +45,7 @@ namespace MapControl
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmap.DownloadFailed -= BitmapDownloadFailed;
BeginOpacityAnimation();
BeginFadeInAnimation();
}
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)

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)