简体   繁体   English

如何使图像显示在我的 Xamarin.Forms 应用程序的 UWP 版本中

[英]How do I make images show up in UWP version of my Xamarin.Forms application

I have a simple Xaml like this:我有一个像这样的简单 Xaml:

...
    <ContentPage.Content>
        <Grid Padding="0,40,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Image  Grid.Row ="0" Source="iMobile"
                        HorizontalOptions="CenterAndExpand"
                        WidthRequest="260" HeightRequest="129"/>
        </Grid>
    </ContentPage.Content>

The image iMobile shows up on Android and ios .图像iMobile显示在Androidios For Android I have the different sizes for the image in the separate drawable folders.对于Android我在单独的可绘制文件夹中具有不同大小的图像。 For ios , I have the different sizes of the image in the Assets catalog.对于ios ,我在 Assets 目录中有不同大小的图像。

I have tried to do same for UWP but nothing seems to work.我试图为 UWP 做同样的事情,但似乎没有任何效果。 Here are some of the things I have tried doing:以下是我尝试做的一些事情:

  • I have added the image to the root directory for the UWP project but that doesn't work.我已将图像添加到 UWP 项目的根目录中,但这不起作用。

  • I added the image to the Assets directory but that did not work.我将图像添加到 Assets 目录中,但这不起作用。

  • I tried adding .scale-100 , .scale-200 and .scale-400 to the name of the image file (tried them all separately) but that did not work.我尝试将.scale-100.scale-200.scale-400到图像文件的名称中(分别尝试),但这不起作用。

  • I also tried putting the image in a directory named scale-100 but that did not work either.我还尝试将图像放在名为scale-100的目录中,但这也不起作用。

Any ideas what might be causing my issue and how I can fix this?任何想法可能导致我的问题以及我如何解决这个问题? It is super frustrating that something this trivial is taking so much of my time.非常令人沮丧的是,这种微不足道的事情占用了我很多时间。

Update: I tried using a URL as the source instead of iMobile and this does not work for UWP either but it does work for Android, and idea why this might be?更新:我尝试使用 URL 作为源而不是 iMobile,这也不适用于 UWP,但它适用于 Android,您知道为什么会这样吗?

How do I make images show up in UWP version of my Xamarin.Forms application如何使图像显示在我的 Xamarin.Forms 应用程序的 UWP 版本中

Please refer Images in Xamarin.Forms official document.请参考Xamarin.Forms官方文档中的图片 Xamarin form support Native resolutions . Xamarin 表单支持本机分辨率

UWP image file names can be suffixed with .scale-xxx before the file extension, where xxx is the percentage of scaling applied to the asset, eg myimage.scale-200.png. UWP 图像文件名可以在文件扩展名前加上 .scale-xxx 后缀,其中 xxx 是应用于资产的缩放百分比,例如 myimage.scale-200.png。 Images can then be referred to in code or XAML without the scale modifier, eg just myimage.png.然后可以在没有缩放修饰符的情况下在代码或 XAML 中引用图像,例如仅 myimage.png。 The platform will select the nearest appropriate asset scale based on the display's current DPI.平台将根据显示器的当前 DPI 选择最接近的适当资产规模。

If you placed image file in the UWP Assets folder, you could use the following xaml, And please note the default blank xamarin app iamge file' color is white, we need set black background to highlight them.如果您将图像文件放置在 UWP Assets 文件夹中,则可以使用以下 xaml,并且请注意默认的空白 xamarin app iamge 文件的颜色为白色,我们需要设置黑色背景以突出显示它们。

<Grid BackgroundColor="Black">
    <Image>
        <Image.Source>
            <OnPlatform x:TypeArguments="FileImageSource">
                <On Platform="UWP" Value="Assets/LargeTile.png" />
                <On Platform="iOS" Value="LargeTile.png" />
                <On Platform="Android" Value="LargeTile.png" />
            </OnPlatform>
        </Image.Source>
    </Image>
</Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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