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
2024-02-03 21:01:53 +01:00
// Copyright © 2024 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
{
private void AnimateImageOpacity()
{
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
{
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;
}
}
}