XAML-Map-Control/MapControl/Tile.WPF.cs
ClemensF 10527c3f0d Version 2.0:
- Support for Windows Phone 8.1 by making MapControl.WinRT a portable library
- Unified TileContainer and MapOverlay implementations across platforms
2014-07-01 18:57:44 +02:00

64 lines
1.9 KiB
C#

// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2014 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace MapControl
{
public partial class Tile
{
public void SetImageSource(ImageSource image, bool animateOpacity)
{
if (image != null && Image.Source == null)
{
if (animateOpacity)
{
var bitmap = image as BitmapSource;
if (bitmap != null && !bitmap.IsFrozen && bitmap.IsDownloading)
{
bitmap.DownloadCompleted += BitmapDownloadCompleted;
bitmap.DownloadFailed += BitmapDownloadFailed;
}
else
{
Image.BeginAnimation(Image.OpacityProperty, new DoubleAnimation(1d, AnimationDuration));
}
}
else
{
Image.Opacity = 1d;
}
}
Image.Source = image;
HasImageSource = true;
}
private void BitmapDownloadCompleted(object sender, EventArgs e)
{
var bitmap = (BitmapSource)sender;
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmap.DownloadFailed -= BitmapDownloadFailed;
Image.BeginAnimation(Image.OpacityProperty, new DoubleAnimation(1d, AnimationDuration));
}
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
{
var bitmap = (BitmapSource)sender;
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmap.DownloadFailed -= BitmapDownloadFailed;
Image.Source = null;
}
}
}