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

65 lines
1.6 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2021-01-13 21:19:27 +01:00
// © 2021 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
2021-07-02 21:18:39 +02:00
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
2021-07-02 21:18:39 +02:00
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
2021-06-14 21:41:37 +02:00
#endif
namespace MapControl
{
public partial class Tile
{
public void SetImage(ImageSource image, bool fadeIn = true)
{
2015-01-20 17:52:02 +01:00
Pending = false;
2020-09-25 15:02:41 +02:00
if (image != null && fadeIn && MapBase.ImageFadeDuration > TimeSpan.Zero)
{
2020-04-16 23:15:03 +02:00
if (image is BitmapImage bitmap && bitmap.UriSource != null)
2017-07-17 21:31:09 +02:00
{
bitmap.ImageOpened += BitmapImageOpened;
bitmap.ImageFailed += BitmapImageFailed;
}
else
{
FadeIn();
}
}
2017-07-17 21:31:09 +02:00
else
{
Image.Opacity = 1d;
}
Image.Source = image;
}
private void BitmapImageOpened(object sender, RoutedEventArgs e)
{
var bitmap = (BitmapImage)sender;
bitmap.ImageOpened -= BitmapImageOpened;
bitmap.ImageFailed -= BitmapImageFailed;
FadeIn();
}
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)
{
var bitmap = (BitmapImage)sender;
bitmap.ImageOpened -= BitmapImageOpened;
bitmap.ImageFailed -= BitmapImageFailed;
Image.Source = null;
}
}
}