Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with tint not applying to loaded images #2077

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ void ApplyTintColor(FrameworkElement platformView, View element, Color? color)

void LoadAndApplyImageTintColor(View element, WImage image, Color color)
{
if (element is IImageElement { Source: UriImageSource uriImageSource })
// Sometimes WImage source doesn't match View source so the image is not ready to be tinted, have to wait for next ImageOpened event
if (element is IImageElement { Source: FileImageSource fileImageSource } &&
image.Source is BitmapImage bitmapImage &&
myix765 marked this conversation as resolved.
Show resolved Hide resolved
Uri.Compare(new Uri($"{bitmapImage.UriSource.Scheme}:///{fileImageSource.File}"), bitmapImage.UriSource, UriComponents.Path, UriFormat.Unescaped, StringComparison.OrdinalIgnoreCase) != 0)
{
image.ImageOpened += OnImageOpened;
}
else if (element is IImageElement { Source: UriImageSource uriImageSource })
{
image.Source = Path.GetExtension(uriImageSource.Uri.AbsolutePath) switch
{
Expand All @@ -140,6 +147,10 @@ void LoadAndApplyImageTintColor(View element, WImage image, Color color)

ApplyTintColor();
}
else if (image.IsLoaded)
{
ApplyTintColor();
}
else
{
image.ImageOpened += OnImageOpened;
Expand Down