Forum Xamarin.Forms

Images not showing in XF OSX project

DaveArkley.7755DaveArkley.7755 USMember
edited January 2018 in Xamarin.Forms

The following is an extract from the XAML or a view whichworks successfully on UWP, Android and iOs platforms:



    
       
        
        
        
       
    
    
        
    
    
        
    


As you can see I've added an On Platform selector for the macOS platform.

While the image appears as expected on other platforms it is not seen on the Mac.

In my OSX project I've added the image to the resources folder and set the build action to 'BundleResource'.

I'm using package Xamarin.Forms 2.5.0.122203.

I can't help thinking I've missed something obvious, can anyone please suggest what I'm doing wrong.

Thanks in advance
Dave

Answers

  • ReinierKops.1905ReinierKops.1905 NLUniversity ✭✭
    edited January 2018

    I'm expecting exactly the same problem. I implemented a custom image render, and see that the image is loaded, but not showing.
    Every other platform is working as expected.

    When I explicite set width and height, the image is visible.

    public class CustomImageRenderer : ImageRenderer
    {
    protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Image> e)
    {
    base.OnElementChanged(e);

            if (Control.Layer.Contents != null && e.NewElement != null)
            {
                this.Element.WidthRequest = Control.Layer.Contents.Width;
                this.Element.HeightRequest = Control.Layer.Contents.Height;
            }
        }
    }
    
  • amirvenusamirvenus USMember ✭✭✭

    on Xamarin.Forms.macOS make sure you do set Width and Height of the Image or it won't show up.

  • WesMarcoWesMarco USMember ✭✭

    Was having the same issue. Setting the WidthRequest and HeightRequest solved it

Sign In or Register to comment.