【问题标题】:where to put images for xamarin forms application在哪里放置 xamarin 表单应用程序的图像
【发布时间】:2016-09-19 14:14:58
【问题描述】:

我正在使用 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" />

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

我把图片放在: - Mobile.Droid\Resources\drawable - 移动.iOS\资源 -Mobile.Windows\资产

但图像在 Windows 8.1 应用程序中根本不显示。 图片尺寸为690*79。

如何解决问题?

【问题讨论】:

  • 可以看这里:developer.xamarin.com/guides/xamarin-forms/working-with/images(注意构建操作选项和平台;))
  • 他们没有注意将图像放置在 Windows 8.1 应用程序的位置
  • 假设没有像您的“header.png”示例这样的文件夹,请将图像放在项目/应用程序的根目录中,并带有Build Action: Content
  • 另请注意,在 Windows 上,按钮上的图像的行为与在 iOS 和 Android 上不同。在 Windows 上,它仍然是普通按钮,但在文本前面有一个小图标。在另外两个上,它类似于 Android 上的 ImageButton。

标签: c# visual-studio xaml xamarin xamarin.forms


【解决方案1】:

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

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

【讨论】:

  • 谢谢,+1.有用。
【解决方案2】:

试试这样的:

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

未测试,但似乎效果不错。

【讨论】:

  • 谢谢,+1.有用。
【解决方案3】:

感谢您的所有帖子,

解决方法是直接将图片资源添加到windows子项目的根目录下。

应使用 Visual Studio 进行添加,以便编译器考虑图像。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多