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

61 lines
1.6 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2019 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
{
public void SetImage(ImageSource image, bool fadeIn = true)
{
2015-01-20 17:52:02 +01:00
Pending = false;
2017-07-17 21:31:09 +02:00
if (fadeIn && FadeDuration > TimeSpan.Zero)
{
var bitmap = image as BitmapSource;
2017-07-17 21:31:09 +02:00
if (bitmap != null && !bitmap.IsFrozen && bitmap.IsDownloading)
2017-07-17 21:31:09 +02:00
{
bitmap.DownloadCompleted += BitmapDownloadCompleted;
bitmap.DownloadFailed += BitmapDownloadFailed;
}
else
{
FadeIn();
}
}
2017-07-17 21:31:09 +02:00
else
{
Image.Opacity = 1d;
}
Image.Source = image;
}
private void BitmapDownloadCompleted(object sender, EventArgs e)
{
var bitmap = (BitmapSource)sender;
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmap.DownloadFailed -= BitmapDownloadFailed;
FadeIn();
}
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
{
var bitmap = (BitmapSource)sender;
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmap.DownloadFailed -= BitmapDownloadFailed;
Image.Source = null;
}
}
}