首页 文章

在哪里为xamarin表单应用程序放置图像

提问于
浏览
1

我正在使用Xamarin为Android,iOS和Visual Studio开发应用程序

我在xaml中添加了以下行来使用图像:

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

第一个用于在 Headers 中显示图像,第二个用于显示按钮图标 . 他们链接相同的图像“header.png”

我把图像放在: - Mobile.Droid \ Resources \ drawable - Mobile.iOS \ Resources -Mobile.Windows \ Assets

但是Windows 8.1应用程序中根本没有显示图像 . 图像大小为690 * 79 .

如何解决这个问题?

3 回答

  • 3

    您必须将图像放在Windows Phone 8,Windows Phone 8.1和UWP应用程序的根项目目录中 .

    本指南将帮助您http://developer.xamarin.com/guides/xamarin-forms/working-with/images

  • 1

    尝试这样的事情:

    <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}" />
    

    要么

    <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>
    

    没有经过测试,但似乎效果很好 .

  • 0

    感谢您的所有帖子,

    解决方案是将图像资源直接添加到根目录下的windows子项目中 .

    应使用visual studio进行添加,以便编译器考虑图像 .

相关问题