【问题标题】:Microsoft Android Emulator Shows Blank Form When DebuggingMicrosoft Android 模拟器在调试时显示空白表单
【发布时间】:2020-01-11 16:41:59
【问题描述】:

我正在尝试在 Visual Studio 的安卓模拟器上运行一个名为“FormsApp”的 Xamarin 表单。模拟器启动良好并呈现。但是,单击“开始调试”后,表单会部署到模拟器,但仅显示空白。

https://i.imgur.com/AbkqDyJ.png

https://i.imgur.com/VttMKfh.png

我也尝试过使用我的 OpenGL ES 渲染器设置和 OpenGL ES API 级别设置。切换到 swiftshader/ANGLE D3D9/ 和兼容性 (OpenGL ES 1.1/2.0) 不起作用。调试的时候还是白屏。

namespace FormsApp
{
    class ContentPageExample : ContentPage
    {
        public ContentPageExample()
        {

            Label labelLarge = new Label
            {
                Text = "Label",
                FontSize = 40,
                HorizontalOptions = LayoutOptions.Center
            };

            Label labelSmall = new Label
            {
                Text = "This control is great for\n" +
                        "displaying one or more\n" +
                        "lines of text.",
                FontSize = 20,
                HorizontalOptions = LayoutOptions.CenterAndExpand
            };

            Button button = new Button
            {
                Text = "Make It So",
                FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Fill
            };

            button.Clicked += (sender, args) =>
            {
                button.Text = "It is so!";
            };

            Entry entry = new Entry
            {
                Placeholder = "Username",
                VerticalOptions = LayoutOptions.Center,
                Keyboard = Keyboard.Text
            };

            BoxView boxView = new BoxView
            {
                Color = Color.Silver,
                WidthRequest = 150,
                HeightRequest = 150,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions = LayoutOptions.Fill
            };

            Image image = new Image
            {
                Source = "monkey.png",
                Aspect = Aspect.AspectFit,
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions = LayoutOptions.Fill
            };

            var tapGestureRecognizer = new TapGestureRecognizer();
            tapGestureRecognizer.Tapped += async (sender, e) =>
            {
                image.Opacity = .5;
                await Task.Delay(200);
                image.Opacity = 1;
            };
            image.GestureRecognizers.Add(tapGestureRecognizer);

            StackLayout stackLayout = new StackLayout
            {
                Children =
                {
                    labelLarge,
                    labelSmall,
                    button,
                    entry,
                    boxView,
                    image
                },
                HeightRequest = 1500
            };

            ScrollView scrollView = new ScrollView
            {
                //BackgroundColor = Color.White,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Content = stackLayout
            };

            //this.BackgroundColor = Color.Black; //White

            // Accomodate iPhone status bar.
            this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

            this.Content = scrollView;

        }

    }
}

没有错误信息..

【问题讨论】:

    标签: c# xamarin.forms visual-studio-2017 cross-platform


    【解决方案1】:

    您是否将ContentPageExample 设置为MainPage?我只是测试了ContentPageExample,它运行良好。

    例如在班级App:

    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
    
            MainPage = new ContentPageExample();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多