Use local function

This commit is contained in:
ClemensFischer 2025-09-10 21:14:18 +02:00
parent f4d43eeb44
commit 3d6fc375b2
2 changed files with 30 additions and 28 deletions

View file

@ -14,17 +14,16 @@ namespace MapControl
{
var image = await loadImageFunc().ConfigureAwait(false);
await Dispatcher.UIThread.InvokeAsync(
() =>
{
Image.Source = image;
void SetImageSource()
{
Image.Source = image;
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
{
var fadeInAnimation = new Animation
{
var fadeInAnimation = new Animation
{
Duration = MapBase.ImageFadeDuration,
Children =
Duration = MapBase.ImageFadeDuration,
Children =
{
new KeyFrame
{
@ -37,11 +36,13 @@ namespace MapControl
Setters = { new Setter(Visual.OpacityProperty, 1d) }
}
}
};
};
_ = fadeInAnimation.RunAsync(Image);
}
});
_ = fadeInAnimation.RunAsync(Image);
}
}
await Dispatcher.UIThread.InvokeAsync(SetImageSource);
}
}
}

View file

@ -14,24 +14,25 @@ namespace MapControl
{
var image = await loadImageFunc().ConfigureAwait(false);
await Image.Dispatcher.InvokeAsync(
() =>
{
Image.Source = image;
void SetImageSource()
{
Image.Source = image;
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
{
if (image is BitmapSource bitmap && !bitmap.IsFrozen && bitmap.IsDownloading)
{
if (image is BitmapSource bitmap && !bitmap.IsFrozen && bitmap.IsDownloading)
{
bitmap.DownloadCompleted += BitmapDownloadCompleted;
bitmap.DownloadFailed += BitmapDownloadFailed;
}
else
{
BeginFadeInAnimation();
}
bitmap.DownloadCompleted += BitmapDownloadCompleted;
bitmap.DownloadFailed += BitmapDownloadFailed;
}
});
else
{
BeginFadeInAnimation();
}
}
}
await Image.Dispatcher.InvokeAsync(SetImageSource);
}
private void BeginFadeInAnimation()