A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
Hello @WoodManEXP ,
Thanks for your question.
- The
ImageOpenedevent doesn't fire on subsequent image loads because UWP caches image by URI. When you set the same BitmapImage URI again (or even create a new BitmapImage with the same URI), UWP recognizes it's already cached and skips the loading process.
Additionally, subscribing to ImageOpened after calling SetSourceAsync means the event may have already fired before you attached the handler.
I recommend disabling image caching and subscribing to events before loading:
This is code example:
private async Task LoadImageWithFadeAsync(StorageFile imageFile)
{
MyStoryboard?.Stop();
Image1.Opacity = 0.0;
var bitmapImage = new BitmapImage();
bitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bitmapImage.ImageOpened += (s, e) =>
{
Debug.WriteLine(" ImageOpened fired!");
Image1.Opacity = 0.0;
MyStoryboard?.Begin();
};
bitmapImage.ImageFailed += (s, e) =>
{
Debug.WriteLine($"Image load failed: {e.ErrorMessage}");
};
using (var fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
{
await bitmapImage.SetSourceAsync(fileStream);
}
Image1.Source = bitmapImage;
}
- After the first animation completes, the Opacity property remains at the final value (1.0). When you try to animate again, the animation tries to go from 0.0 to 1.0, but since the current value is already 1.0, it appears to jump immediately to the end state. I recommend resetting the opacity before each animation
private async Task LoadImageWithFadeAsync(StorageFile imageFile)
{
MyStoryboard?.Stop();
Image1.Opacity = 0.0;
var bitmapImage = new BitmapImage();
bitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bitmapImage.ImageOpened += (s, e) =>
{
Image1.Opacity = 0.0;
MyStoryboard?.Begin();
};
using (var fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
{
await bitmapImage.SetSourceAsync(fileStream);
}
Image1.Source = bitmapImage;
}
Note: I noticed your XAML uses <Image.Triggers>. Unfortunately, EventTriggers are not commonly used in UWP. The only trigger that is typically defined is a Loaded trigger (not Image).
Please try and let me know it it works.
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.