XAML-Map-Control/MapControl/UWP/TileImageLoader.UWP.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2017-08-04 21:38:58 +02:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2025-01-01 18:57:55 +01:00
// Copyright © Clemens Fischer
2017-08-04 21:38:58 +02:00
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Threading.Tasks;
using Windows.UI.Core;
using Windows.UI.Xaml.Media;
2017-08-04 21:38:58 +02:00
namespace MapControl
{
public partial class TileImageLoader
2017-08-04 21:38:58 +02:00
{
2025-01-26 22:40:33 +01:00
private static async Task LoadTileImage(Tile tile, Func<Task<ImageSource>> loadImageFunc)
{
var tcs = new TaskCompletionSource<object>();
async void LoadTileImage()
{
try
{
var image = await loadImageFunc();
2025-01-21 19:28:49 +01:00
tcs.TrySetResult(null); // tcs.Task has completed when image is loaded
tile.SetImageSource(image);
}
catch (Exception ex)
{
tcs.TrySetException(ex);
}
2021-07-05 00:03:44 +02:00
}
2025-01-21 19:28:49 +01:00
if (!await tile.Image.Dispatcher.TryRunAsync(CoreDispatcherPriority.Low, LoadTileImage))
{
tcs.TrySetCanceled();
}
2025-01-21 19:28:49 +01:00
await tcs.Task;
}
2017-08-04 21:38:58 +02:00
}
}