Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Is it possible to load an image from the Android project as an icon used on a Xamarin.Forms PCL XAML

JKnottJKnott Member ✭✭✭

Hello, I've asked part of this question already, but not sure I can figure out what to do here.
I am creating a Master Detail view based project. The flyout menu that has the list of pages, is boring, so I am trying to add icons to each menu option.
I see tons of code and samples, for loading png, jpg, files from within the PCL project it's self. But is there a way to select an icon or drawable from the android project to use in the PCL project?

For the moment my XAML looks like this at the point where it creates the menu options.

                    <Grid Padding="8">
                        <Image Source="{Binding Icon}" />
                            d:Text="{Binding .}"
                            Text="{Binding Title}" />

And then in the cs file, I am setting the Icon member (which I had created in the menu class)

        ImageSource invIcon = ImageSource.FromResource("MyApp.Resource.ic_bank.png");
        menuItems = new List<HomeMenuItem>
            new HomeMenuItem {Id = MenuItemType.Inventory, Title="DetailItem", Icon=invIcon },
            new HomeMenuItem {Id = MenuItemType.LoadData, Title="LoadData", Icon=invIcon  },
            new HomeMenuItem {Id = MenuItemType.About, Title="About", Icon=invIcon  }

(Yes I know I am shorting it to use the same icon across all 3, I am just trying to get it to "work" before I start adding and getting other icons.
For the moment the icons are just Material Icons I've added using the handy VS plugin.

If I need to add all the icons to platform specific folders within the PCL project, that's fine (and what I may end up doing at any rate). I was just curious if I could share and jump between the platform code and the PCL code to make the binaries smaller.

Thanks for any assistance, or confirmation I've been chasing my tail for the last day and a half LOL

Best Answer


  • JKnottJKnott Member ✭✭✭

    LOL and I just noticed, I forgot to put the and the

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Ok, If you solved it by yourself, please mark you reply as answer, it will help others who have similar issue. Thanks.

  • JKnottJKnott Member ✭✭✭

    LOL Nope, was just pointing out an error in my code... Will just remove my comment...

  • JKnottJKnott Member ✭✭✭
    edited July 2019

    Excellent! that's exactly what I was wondering. Thanks! I was getting ready to just move the images to the PCL project, and load them there.

    Update, just plugged it in, and works exactly as I wanted, Thanks again! I'm sorry to be asking fairly dunce questions. I've been trying to get back into programming and engineering, but have about 9 years and one fairly major TBI to contend with. LOL At least I can remember my name! (well most days! LOL)

Sign In or Register to comment.