Xamarin白屏在本地机器上

时间:2018-10-05 08:46:19

标签: xamarin

enter image description here

你好, 我对Xamarin遇到问题,当我运行程序时,只能看到白屏,就像在图片上一样。 MainPage.xaml.cs具有以下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace Hello
{
public class App : Application
{
    public App()
        { // The root page of your application 
            MainPage = new ContentPage
            {
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children = {
                        new Label {
                            HorizontalTextAlignment = TextAlignment.Center,
                            Text = "Welcome to Xamarin Forms!"
                        }
                    }
                }
            };
        }
        protected override void OnStart()
        {
            // Handle when your app starts 
        }
        protected override void OnSleep()
        {
            // Handle when your app sleeps 
        } 
        protected override void OnResume()
        {
            // Handle when your app resumes 
        }
    }
}

我从“使用Xamarin表单创建移动应用程序”中获取此代码,有人知道该程序有什么问题吗?

1 个答案:

答案 0 :(得分:0)

在部分项目的共享项目的 App.xaml.cs类中编写代码。您上面显示的代码不是局部类。可能是因为屏幕快照显示您已经在Main.axml.cs文件中编写了App类代码

using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace App
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            //MainPage = new MainPage();
            MainPage = new ContentPage
            {
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children =
                    {
                        new Label
                        {
                            HorizontalTextAlignment=TextAlignment.Center,
                            Text="Welcome to xamarin forms"
                        }
                    }
                }
            };
        }
    }
}