mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-08 16:05:50 +00:00
Updated TileImageLoader and ImageFileCache for WinUI
This commit is contained in:
parent
9ebc88204b
commit
a9475f79fe
7 changed files with 90 additions and 75 deletions
|
|
@ -3,54 +3,20 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
#if WINUI
|
||||
using Microsoft.System;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
#else
|
||||
using Windows.UI.Core;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
#else
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class Tile
|
||||
{
|
||||
public async Task SetImageAsync(Func<Task<ImageSource>> loadImageFunc)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<object>();
|
||||
|
||||
async void callback()
|
||||
{
|
||||
try
|
||||
{
|
||||
SetImage(await loadImageFunc());
|
||||
tcs.SetResult(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tcs.SetException(ex);
|
||||
}
|
||||
}
|
||||
#if WINUI
|
||||
if (!Image.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, callback))
|
||||
{
|
||||
// should never happen, but just in case: reset Pending state and complete TaskCompletionSource
|
||||
Pending = true;
|
||||
tcs.SetResult(null);
|
||||
}
|
||||
#else
|
||||
_ = Image.Dispatcher.RunAsync(CoreDispatcherPriority.Low, callback);
|
||||
#endif
|
||||
_ = await tcs.Task.ConfigureAwait(false); // wait until image loading in UI thread is completed
|
||||
}
|
||||
|
||||
public void SetImage(ImageSource image, bool fadeIn = true)
|
||||
{
|
||||
Pending = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue