我的Xamarin.forms图片未加载,您能帮我吗?

时间:2018-12-08 19:31:35

标签: c# xamarin xamarin.forms xamarin.ios xamarin.android

我正在尝试制作一个跨平台应用程序,并且正在尝试创建一个SplashScreen。 我已将所有图像添加到“资源”文件夹中,并将它们放入“嵌入式”资源中,但看不到它们。 Ressource folder

The result I got

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:DVHub"
         x:Class="DVHub.MainPage">
    <ContentPage.Content>
        <StackLayout VerticalOptions="FillAndExpand"
                HorizontalOptions="FillAndExpand"
                Orientation="Vertical"
                BackgroundColor="White">
            <Image x:Name="logo" 
                   Scale="1.4"
                   TranslationX="-120"
                   TranslationY="35"/>
            <Image x:Name="splashScreen"  
                   Scale="1.2"
                   TranslationY="120"/>
        </StackLayout>
</ContentPage.Content>

表单类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Timers;

namespace DVHub
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);
            logo.Source = ImageSource.FromFile("logo.png");
            splashScreen.Source = ImageSource.FromFile("splashScreen.png");
            Timer timer = new Timer
            {
                Interval = 3000,
                AutoReset = false
            };
            timer.Elapsed += Timer_Elapsed;
            timer.Start();
        }
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            // await Navigation.PushAsync(new Infos(), true);
            Application.Current.MainPage = new NavigationPage(new Infos());
        }
    }
}

预先感谢

louga31

1 个答案:

答案 0 :(得分:0)

我不确定ios,但是对于android,您应该将Build Action设置为AndroidResource。希望会对您有所帮助。