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

44 lines
1.2 KiB
C#
Raw Normal View History

2017-08-04 21:38:58 +02:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2024-02-03 21:01:53 +01:00
// Copyright © 2024 Clemens Fischer
2017-08-04 21:38:58 +02:00
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Threading.Tasks;
2024-02-13 20:51:22 +01:00
using Windows.Storage;
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
{
/// <summary>
2024-02-08 21:36:46 +01:00
/// Default folder where the Cache instance may save data.
2017-08-04 21:38:58 +02:00
/// </summary>
2024-02-13 20:51:22 +01:00
public static string DefaultCacheFolder => ApplicationData.Current.TemporaryFolder.Path;
2017-08-04 21:38:58 +02:00
private static async Task LoadTileAsync(Tile tile, Func<Task<ImageSource>> loadImageFunc)
{
var tcs = new TaskCompletionSource<object>();
2021-07-05 00:03:44 +02:00
async void callback()
{
try
{
2022-11-17 23:11:40 +01:00
tile.SetImageSource(await loadImageFunc());
tcs.TrySetResult(null);
}
catch (Exception ex)
{
tcs.TrySetException(ex);
}
2021-07-05 00:03:44 +02:00
}
await tile.Image.Dispatcher.RunAsync(CoreDispatcherPriority.Low, callback);
await tcs.Task.ConfigureAwait(false);
}
2017-08-04 21:38:58 +02:00
}
}