Changing ElmSharp.Image.Color with Xamarin Forms

Changing ElmSharp.Image.Color with Xamarin Forms

BY 31 Jan 2021 Tizen .NET

I’m trying to figure out how to tint an image using Xamarin Forms’ Image control. I’ve setup a custom ImageRenderer, linking it to the Image clasy by exporting the renderer attribute using :

 

[assembly: ExportRenderer(typeof(VImage), typeof(VImageRenderer))]
namespace TizenWatchfaceTest
{
    public class VImageRenderer : ImageRenderer
	{
		public static void Init()
		{
		}

		protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
		{
			SetTint();

			base.OnElementChanged(e);
		}

		protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			if (e.PropertyName == VImage.TintColorProperty.PropertyName || e.PropertyName == VImage.SourceProperty.PropertyName)
				SetTint();

			base.OnElementPropertyChanged(sender, e);
		}

		void SetTint()
		{
			if (Control == null || Element == null)
				return;

			VImage vi = Element as VImage;

			Control.Color = vi.TintColor.ToNative();
		}
	}
}

 

VImage just extends Xamarin.Forms.Image, adding a bindable property for the tint color. I can’t tell at the moment if this approach is supported with Tizen.Net or if ElmSharp.Image.Color doesn’t work the way I think it does. The result right now on my watch is no tinting at all.

 

Is there a better approach to tint an image with Tizen.Net? I initially played with setting BackgroundColor in Xamarin.Forms.Image, but if you have any transparent pixels in your image, they show up colored (which is not the behavior I want).

Written by