XAML-Map-Control/MapControl/Avalonia/ImageTile.Avalonia.cs

51 lines
1.5 KiB
C#
Raw Normal View History

2025-08-19 19:43:02 +02:00
using Avalonia;
using Avalonia.Animation;
2025-11-13 15:32:01 +01:00
using Avalonia.Controls;
using Avalonia.Media;
2025-08-19 19:43:02 +02:00
using Avalonia.Styling;
using System;
using System.Threading.Tasks;
2025-01-05 09:22:50 +01:00
2026-04-13 17:14:49 +02:00
namespace MapControl;
public class ImageTile(int zoomLevel, int x, int y, int columnCount)
: Tile(zoomLevel, x, y, columnCount)
2024-05-19 23:23:27 +02:00
{
2026-04-13 17:14:49 +02:00
public Image Image { get; } = new Image { Stretch = Stretch.Fill };
public override async Task LoadImageAsync(Func<Task<IImage>> loadImageFunc)
2024-05-19 23:23:27 +02:00
{
2026-04-13 17:14:49 +02:00
var image = await loadImageFunc().ConfigureAwait(false);
2025-11-13 15:32:01 +01:00
2026-04-13 17:14:49 +02:00
void SetImageSource()
2024-05-19 23:23:27 +02:00
{
2026-04-13 17:14:49 +02:00
Image.Source = image;
2026-04-13 17:14:49 +02:00
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
2025-09-10 21:14:18 +02:00
{
2026-04-13 17:14:49 +02:00
var fadeInAnimation = new Animation
2025-09-10 21:14:18 +02:00
{
2026-04-13 17:14:49 +02:00
Duration = MapBase.ImageFadeDuration,
Children =
{
new KeyFrame
{
2026-04-13 17:14:49 +02:00
KeyTime = TimeSpan.Zero,
Setters = { new Setter(Visual.OpacityProperty, 0d) }
},
new KeyFrame
{
KeyTime = MapBase.ImageFadeDuration,
Setters = { new Setter(Visual.OpacityProperty, 1d) }
}
2026-04-13 17:14:49 +02:00
}
};
2025-09-10 21:14:18 +02:00
2026-04-13 17:14:49 +02:00
_ = fadeInAnimation.RunAsync(Image);
2025-09-10 21:14:18 +02:00
}
2024-05-19 23:23:27 +02:00
}
2026-04-13 17:14:49 +02:00
await Image.Dispatcher.InvokeAsync(SetImageSource);
2024-05-19 23:23:27 +02:00
}
}