Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to Add embedded image in Shared project not in PCL?

$
0
0

Hello,

I tried to add embedded image in my shared project.

I created Shared project for Android & IOS.

Added images in shared project.

For rendering, in XAML file :

in same namespace **AllControl **I implemented interface IMarkupExtension.

[Preserve(AllMembers = true)]
[ContentProperty(nameof(Source))]
public class ImageResourceExtension : IMarkupExtension
{
public string Source { get; set; }

    public object ProvideValue(IServiceProvider serviceProvider)
    {
        if (Source == null)
        {
            return null;
        }
        // Do your translation lookup here, using whatever method you require, typeof(ImageResourceExtension).GetTypeInfo().Assembly
        Console.WriteLine(typeof(ImageResourceExtension).GetTypeInfo().Assembly);
        var imageSource = ImageSource.FromFile(Source);
        return imageSource;
    }
}

Set image property Build Action as Embedded resource

Same code is working fine for PCL.

Please give suggestion for Shared project.

Thank you


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>