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

48 lines
1.3 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2022-01-14 20:22:56 +01:00
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace MapControl
{
public partial class Tile
{
2022-11-19 18:00:26 +01:00
private void AnimateImageOpacity()
{
2022-11-19 18:00:26 +01:00
if (Image.Source is BitmapSource bitmap && !bitmap.IsFrozen && bitmap.IsDownloading)
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
{
2022-11-19 18:00:26 +01:00
BeginOpacityAnimation();
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;
2022-11-19 18:00:26 +01:00
BeginOpacityAnimation();
}
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
{
var bitmap = (BitmapSource)sender;
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmap.DownloadFailed -= BitmapDownloadFailed;
Image.Source = null;
}
}
}