ProEns08
ProEns08

Reputation: 1914

where to put images for xamarin forms application

I am developing an application for Android, iOS and Visual Studio using Xamarin

I added the following lines in xaml to use images:

<Image Source="header.png" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
<Button x:Name="Object_Detection" Image="header.png" />

The first is for displaying an image in the header and the second is for displaying a button icon. They link for the same image "header.png"

I put the image under: - Mobile.Droid\Resources\drawable - Mobile.iOS\Resources -Mobile.Windows\Assets

But the image is not shown at all in the Windows 8.1 app. the image size is 690*79.

how to resolve the problem?

Upvotes: 4

Views: 7428

Answers (3)

ProEns08
ProEns08

Reputation: 1914

Thanks for all your posts,

the solution was to add the image resource to the windows sub-project directly under the root.

The addition should be made using visual studio so that the image will be taken in consideration by the compiler.

Upvotes: 0

Yksh
Yksh

Reputation: 3306

Try something like this :

  <ContentPage.Resources>
        <ResourceDictionary>
            <OnPlatform x:Key="ImageHeaders" 
                        x:TypeArguments="ImageSource"
                        iOS="header.png"
                        Android="header.png"
                        WinPhone="Assets/header.png" />
       </ResourceDictionary>
  </ContentPage.Resources>

  <Image Source="{StaticResource ImageHeaders}" />

OR

  <Image.Source>
    <OnPlatform x:TypeArguments="ImageSource">
      <OnPlatform.iOS><FileImageSource File="header.png"/></OnPlatform.iOS>
      <OnPlatform.Android><FileImageSource File="header.png"/></OnPlatform.Android>
      <OnPlatform.WinPhone><FileImageSource File="Assets/header.png"/></OnPlatform.WinPhone>
    </OnPlatform>
  </Image.Source>

Not tested, but it seems to work well.

Upvotes: 3

Abdul Muhaymin
Abdul Muhaymin

Reputation: 113

You have to place images in the root Project directory for Windows Phone 8, Windows Phone 8.1 and UWP applications.

This guide will help you http://developer.xamarin.com/guides/xamarin-forms/working-with/images

Upvotes: 4

Related Questions