2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2013-05-07 18:12:25 +02:00
|
|
|
|
// Copyright © Clemens Fischer 2012-2013
|
2012-11-22 21:42:29 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2012-12-09 22:18:31 +01:00
|
|
|
|
#if NETFX_CORE
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
|
using Windows.UI.Xaml.Media;
|
2013-04-21 23:56:08 +02:00
|
|
|
|
using Windows.UI.Xaml.Media.Animation;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using Windows.UI.Xaml.Media.Imaging;
|
|
|
|
|
|
#else
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Media;
|
2013-04-21 23:56:08 +02:00
|
|
|
|
using System.Windows.Media.Animation;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2013-01-03 15:33:46 +01:00
|
|
|
|
public partial class Tile
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-04-21 23:56:08 +02:00
|
|
|
|
public readonly Image Image = new Image { Opacity = 0d };
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
public ImageSource ImageSource
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Image.Source; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-03 15:33:46 +01:00
|
|
|
|
public void SetImageSource(ImageSource image, bool animateOpacity)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-01-17 18:48:38 +01:00
|
|
|
|
if (image != null && Image.Source == null)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (animateOpacity)
|
|
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
var bitmap = image as BitmapImage;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
2013-11-12 21:14:53 +01:00
|
|
|
|
if (bitmap != null)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
bitmap.ImageOpened += BitmapImageOpened;
|
|
|
|
|
|
bitmap.ImageFailed += BitmapImageFailed;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2013-05-07 18:12:25 +02:00
|
|
|
|
Image.BeginAnimation(Image.OpacityProperty, new DoubleAnimation { To = 1d, Duration = AnimationDuration });
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Image.Opacity = 1d;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-03 15:33:46 +01:00
|
|
|
|
Image.Source = image;
|
2013-11-12 21:14:53 +01:00
|
|
|
|
HasImageSource = true;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BitmapImageOpened(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
var bitmap = (BitmapImage)sender;
|
|
|
|
|
|
|
|
|
|
|
|
bitmap.ImageOpened -= BitmapImageOpened;
|
|
|
|
|
|
bitmap.ImageFailed -= BitmapImageFailed;
|
|
|
|
|
|
|
2013-05-07 18:12:25 +02:00
|
|
|
|
Image.BeginAnimation(Image.OpacityProperty, new DoubleAnimation { To = 1d, Duration = AnimationDuration });
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)
|
|
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
var bitmap = (BitmapImage)sender;
|
|
|
|
|
|
|
|
|
|
|
|
bitmap.ImageOpened -= BitmapImageOpened;
|
|
|
|
|
|
bitmap.ImageFailed -= BitmapImageFailed;
|
|
|
|
|
|
|
2013-01-03 15:33:46 +01:00
|
|
|
|
Image.Source = null;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|