locked
Loading an Image from a Resource in xaml RRS feed

  • Question

  • User378777 posted

    I have a resource called biglogo.png added via the Resource menu and now it's in the Resources folder of my project.

    I want to use it via xaml but neither
    WidthRequest="80" HeightRequest="80"/> nor

    WidthRequest="80" HeightRequest="80"/>

    seem to work. Is there a straightforward way to make it work?

    Wednesday, December 5, 2018 2:00 PM

All replies

  • User219438 posted

    This >> https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images

    Specifically the Local Images section.

    Adding it to an asset catalog in iOS https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/displaying-an-image?tabs=windows is I think the preferred solution for iOS

    Wednesday, December 5, 2018 3:06 PM
  • User369978 posted

    where does that Resources folder ? Forms Project ? iOS or Android project ?

    Thursday, December 6, 2018 5:40 AM
  • User378777 posted

    The Resource folder of the Forms project.

    Thursday, December 13, 2018 3:43 PM
  • User369978 posted

    @ChristianKl said: The Resource folder of the Forms project.

    Refer https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=macos

    Image files can be added to each application project and referenced from Xamarin.Forms shared code.

    Move those image from Forms project to iOS/Android project .

    Monday, December 17, 2018 6:05 AM
  • User378777 posted

    Are you saying that it's impossible to load images from the Resources in the Forms project?

    Tuesday, December 18, 2018 9:22 AM
  • User369978 posted

    @ChristianKl said: Are you saying that it's impossible to load images from the Resources in the Forms project?

    No , but we strongly recommend you place the image into the native project .

    And if you want, i can post the code that accessing image from Forms project .

    Tuesday, December 18, 2018 9:28 AM
  • User76049 posted

    @ChristianKl said: Are you saying that it's impossible to load images from the Resources in the Forms project?

    If you read the link, there's a section on loading local image resources for in XAML, you need a value converter.

    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=macos#using-xaml

    If the image is an embedded resource within your platform specific project you can just reference the filename in your image control

    Tuesday, December 18, 2018 9:30 AM