简体   繁体   中英

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?

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM