首页 文章

显示来自URL Xamarin.Forms的图像

提问于
浏览
5

我正在使用此代码来显示带有URL的图像

的.xaml

<?xml version="1.0" encoding="UTF-8"?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="LandAHand.VolunteerView">
        <ContentPage.Content>
             <AbsoluteLayout BackgroundColor="Maroon">
                 <Image x:Name="backgroundImage" AbsoluteLayout.LayoutBounds="0,0,1,1"   AbsoluteLayout.LayoutFlags="All" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill"/>
             </AbsoluteLayout>
        </ContentPage.Content>
    </ContentPage>

的.cs

using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace LandAHand
{
    public partial class VolunteerView : ContentPage
    {
        public VolunteerView()
        {
            InitializeComponent();
            backgroundImage.Source = new UriImageSource
            {
                Uri = new Uri("https://s9.postimg.org/aq1jt3fu7/handshake_87122244_std.jpg"),
                CachingEnabled = true,
                CacheValidity = new TimeSpan(5, 0, 0, 0)
            };
        }
    }
}

此代码成功使用iOS但不使用android .

1 回答

  • 3

    嗯,你可以用你的Xaml更容易做到这一点,只需像这样制作你的xaml

    <Image x:Name="backgroundImage" Source="https://s9.postimg.org/aq1jt3fu7/handshake_87122244_std.jpg" AbsoluteLayout.LayoutBounds="0,0,1,1"   AbsoluteLayout.LayoutFlags="All" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill"/>
    

    并删除后面代码中的相关代码 . 默认情况下,24小时启用兑现

相关问题