mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Moved asynchronous image loading to Tile class
This commit is contained in:
parent
2f9c50fb47
commit
f4d43eeb44
10 changed files with 114 additions and 184 deletions
|
|
@ -1,33 +1,47 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class Tile
|
||||
{
|
||||
private void FadeIn()
|
||||
public async Task LoadImageAsync(Func<Task<IImage>> loadImageFunc)
|
||||
{
|
||||
var fadeInAnimation = new Animation
|
||||
{
|
||||
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) }
|
||||
}
|
||||
}
|
||||
};
|
||||
var image = await loadImageFunc().ConfigureAwait(false);
|
||||
|
||||
_ = fadeInAnimation.RunAsync(Image);
|
||||
await Dispatcher.UIThread.InvokeAsync(
|
||||
() =>
|
||||
{
|
||||
Image.Source = image;
|
||||
|
||||
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
|
||||
{
|
||||
var fadeInAnimation = new Animation
|
||||
{
|
||||
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) }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_ = fadeInAnimation.RunAsync(Image);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class TileImageLoader
|
||||
{
|
||||
private static async Task LoadTileImage(Tile tile, Func<Task<IImage>> loadImageFunc)
|
||||
{
|
||||
var image = await loadImageFunc().ConfigureAwait(false);
|
||||
|
||||
await Dispatcher.UIThread.InvokeAsync(() => tile.SetImageSource(image));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue