XAML-Map-Control/MapControl/Tile.Silverlight.WinRT.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

72 lines
2.1 KiB
C#

// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2014 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if WINDOWS_RUNTIME
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Media.Imaging;
#else
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
#endif
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 BitmapImage;
if (bitmap != null)
{
bitmap.ImageOpened += BitmapImageOpened;
bitmap.ImageFailed += BitmapImageFailed;
}
else
{
Image.BeginAnimation(Image.OpacityProperty, new DoubleAnimation { To = 1d, Duration = AnimationDuration });
}
}
else
{
Image.Opacity = 1d;
}
}
Image.Source = image;
HasImageSource = true;
}
private void BitmapImageOpened(object sender, RoutedEventArgs e)
{
var bitmap = (BitmapImage)sender;
bitmap.ImageOpened -= BitmapImageOpened;
bitmap.ImageFailed -= BitmapImageFailed;
Image.BeginAnimation(Image.OpacityProperty, new DoubleAnimation { To = 1d, Duration = AnimationDuration });
}
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)
{
var bitmap = (BitmapImage)sender;
bitmap.ImageOpened -= BitmapImageOpened;
bitmap.ImageFailed -= BitmapImageFailed;
Image.Source = null;
}
}
}