XAML-Map-Control/MapControl/UWP/MapImageLayer.UWP.cs

58 lines
1.5 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2017 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
2016-02-23 20:07:30 +01:00
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
namespace MapControl
{
public partial class MapImageLayer
{
protected void UpdateImage(Uri uri)
{
2017-08-04 21:38:58 +02:00
UpdateImage(uri != null ? new BitmapImage(uri) : null);
2016-02-23 20:07:30 +01:00
}
2017-08-04 21:38:58 +02:00
protected void UpdateImage(BitmapSource bitmapSource)
2016-02-23 20:07:30 +01:00
{
2017-08-04 21:38:58 +02:00
SetTopImage(bitmapSource);
2016-02-23 20:07:30 +01:00
2017-08-04 21:38:58 +02:00
var bitmapImage = bitmapSource as BitmapImage;
if (bitmapImage != null)
{
bitmapImage.ImageOpened += BitmapImageOpened;
bitmapImage.ImageFailed += BitmapImageFailed;
}
else
{
SwapImages();
}
}
private void BitmapImageOpened(object sender, RoutedEventArgs e)
{
2017-08-04 21:38:58 +02:00
var bitmapImage = (BitmapImage)sender;
bitmapImage.ImageOpened -= BitmapImageOpened;
bitmapImage.ImageFailed -= BitmapImageFailed;
SwapImages();
}
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)
{
2017-08-04 21:38:58 +02:00
var bitmapImage = (BitmapImage)sender;
bitmapImage.ImageOpened -= BitmapImageOpened;
bitmapImage.ImageFailed -= BitmapImageFailed;
((Image)Children[topImageIndex]).Source = null;
SwapImages();
}
}
}