Xamarin.Forms.Mac use embedded images with imageresource markup extension

HelgeKeckHelgeKeck DEMember ✭✭
edited September 2018 in Xamarin.Forms

Hi,

im trying to port and existing Xamarin.Forms project to Xamarin.Forms.Mac.

i have embedded images in the shared project and want to use them in the Mac OS Version of the APP. It works on Andorid, iOS and UWP, but cant get it working on Mac OS.

Xaml code:
<Image Margin="10" Source="{local:ImageResource myApp.Assets.logo.png}"/>

Imageresource Extension:

[ContentProperty("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
            var imageSource = ImageSource.FromResource(Source);

            return imageSource;
        }
    }

any ideas why this happens?

Best Answer

  • HelgeKeckHelgeKeck DE ✭✭
    Accepted Answer

    it seems macOS Forms requires to set WidthRequest and HighRequest to display images. it works now. thanks anyway

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Check https://docs.microsoft.com/en-us/xamarin/mac/app-fundamentals/image

    Where do you place that image , Resources folder or Asset Catalog Image Sets?

  • HelgeKeckHelgeKeck DEMember ✭✭

    thanks, i know this page but this is a Xamarin.Forms Application and the Images are embedded in the shared Project and want to use them with the imageresource Markup Extension. since it works on iOS too, it should also work in Mac OS i guess

  • HelgeKeckHelgeKeck DEMember ✭✭
    Accepted Answer

    it seems macOS Forms requires to set WidthRequest and HighRequest to display images. it works now. thanks anyway

Sign In or Register to comment.