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

53 lines
1.7 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 Avalonia.Threading;
2025-08-19 19:43:02 +02:00
using System;
using System.Threading.Tasks;
2025-01-05 09:22:50 +01:00
2024-05-19 23:23:27 +02:00
namespace MapControl
{
2025-11-13 15:32:01 +01:00
public class ImageTile(int zoomLevel, int x, int y, int columnCount)
: Tile(zoomLevel, x, y, columnCount)
2024-05-19 23:23:27 +02:00
{
2025-11-13 15:32:01 +01: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
{
var image = await loadImageFunc().ConfigureAwait(false);
2025-09-10 21:14:18 +02:00
void SetImageSource()
{
Image.Source = image;
2025-09-10 21:14:18 +02:00
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
{
var fadeInAnimation = new Animation
2025-01-05 09:22:50 +01:00
{
2025-09-10 21:14:18 +02:00
Duration = MapBase.ImageFadeDuration,
Children =
{
new KeyFrame
{
KeyTime = TimeSpan.Zero,
Setters = { new Setter(Visual.OpacityProperty, 0d) }
},
new KeyFrame
{
KeyTime = MapBase.ImageFadeDuration,
Setters = { new Setter(Visual.OpacityProperty, 1d) }
}
}
2025-09-10 21:14:18 +02:00
};
_ = fadeInAnimation.RunAsync(Image);
}
}
2025-01-05 09:22:50 +01:00
2025-09-10 21:14:18 +02:00
await Dispatcher.UIThread.InvokeAsync(SetImageSource);
2024-05-19 23:23:27 +02:00
}
}
}