XAML-Map-Control/MapControl/WPF/Tile.WPF.cs

62 lines
1.7 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2025-01-01 18:57:55 +01:00
// Copyright © Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace MapControl
{
public partial class Tile
{
2025-01-05 10:31:15 +01:00
private void BeginFadeInAnimation()
{
2025-01-05 10:31:15 +01:00
var fadeInAnimation = new DoubleAnimation
{
From = 0d,
Duration = MapBase.ImageFadeDuration,
FillBehavior = FillBehavior.Stop
};
Image.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
}
2025-01-05 10:31:15 +01:00
private void FadeIn()
{
if (Image.Source is BitmapSource bitmap && bitmap.IsDownloading && !bitmap.IsFrozen)
2017-07-17 21:31:09 +02:00
{
2022-11-19 18:00:26 +01:00
bitmap.DownloadCompleted += BitmapDownloadCompleted;
bitmap.DownloadFailed += BitmapDownloadFailed;
}
2017-07-17 21:31:09 +02:00
else
{
2025-01-05 10:31:15 +01:00
BeginFadeInAnimation();
2017-07-17 21:31:09 +02:00
}
}
private void BitmapDownloadCompleted(object sender, EventArgs e)
{
var bitmap = (BitmapSource)sender;
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmap.DownloadFailed -= BitmapDownloadFailed;
2025-01-05 10:31:15 +01:00
BeginFadeInAnimation();
}
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
{
var bitmap = (BitmapSource)sender;
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmap.DownloadFailed -= BitmapDownloadFailed;
Image.Source = null;
}
}
}