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

70 lines
1.9 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2025-01-01 18:57:55 +01:00
// Copyright © Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
2024-05-22 11:25:32 +02:00
#if UWP
2021-07-02 21:18:39 +02:00
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Animation;
2021-07-02 21:18:39 +02:00
using Windows.UI.Xaml.Media.Imaging;
2024-05-22 11:25:32 +02:00
#else
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media.Animation;
using Microsoft.UI.Xaml.Media.Imaging;
2021-06-14 21:41:37 +02:00
#endif
namespace MapControl
{
public partial class Tile
{
private void BeginOpacityAnimation()
{
2025-01-05 09:22:50 +01:00
var animation = new DoubleAnimation
{
From = 0d,
Duration = MapBase.ImageFadeDuration,
FillBehavior = FillBehavior.Stop
};
Storyboard.SetTargetProperty(animation, nameof(UIElement.Opacity));
Storyboard.SetTarget(animation, Image);
var storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Begin();
}
private void AnimateImageOpacity()
{
if (Image.Source is BitmapImage bitmap && bitmap.UriSource != null)
{
2022-11-19 18:00:26 +01:00
bitmap.ImageOpened += BitmapImageOpened;
bitmap.ImageFailed += BitmapImageFailed;
}
2017-07-17 21:31:09 +02:00
else
{
2022-11-19 18:00:26 +01:00
BeginOpacityAnimation();
2017-07-17 21:31:09 +02:00
}
}
private void BitmapImageOpened(object sender, RoutedEventArgs e)
{
var bitmap = (BitmapImage)sender;
bitmap.ImageOpened -= BitmapImageOpened;
bitmap.ImageFailed -= BitmapImageFailed;
2022-11-19 18:00:26 +01:00
BeginOpacityAnimation();
}
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)
{
var bitmap = (BitmapImage)sender;
bitmap.ImageOpened -= BitmapImageOpened;
bitmap.ImageFailed -= BitmapImageFailed;
Image.Source = null;
}
}
}