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
2023-01-03 15:12:53 +01:00
// Copyright © 2023 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
{
2023-08-21 20:48:51 +02:00
private void AnimateImageOpacity(ImageSource image)
{
2023-08-21 20:48:51 +02:00
if (image 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;
}
}
}