【问题标题】:Cannot implicily convert type to 'Xamarin.Forms.Page'无法将类型隐式转换为“Xamarin.Forms.Page”
【发布时间】:2016-09-27 22:18:44
【问题描述】:

我有一个 Xamarin Forms 项目,我更新了 Xamarin,这是新的 App.cs

public App()
{
    // The root page of your application
    var content = new ContentPage
    {
        Title = "Proje1",
        Content = new StackLayout
        {
            VerticalOptions = LayoutOptions.Center,
            Children = {
                new Label {
                    HorizontalTextAlignment = TextAlignment.Center,
                    Text = "Welcome to Xamarin Forms!"
                    }
                }
         }
    };

    MainPage = new NavigationPage(content);
}

我收到此错误

无法将类型“Proje1.Views.View1”隐式转换为“Xamarin.Forms.Page”

当我做这个时

MainPage = new View1();

我之前是这样指向的,现在应该如何在App.cs中设置初始页面?

【问题讨论】:

  • 什么是“View1” - 不在您的示例代码中?
  • 我被改名了

标签: xamarin xamarin.forms


【解决方案1】:

我假设View1 以某种方式从ContentView 继承,所以您需要将其嵌入到Page 中,因此它适合用作Application.MainPage

MainPage = new ContentPage {
  Content = new View1()
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-18
    • 2022-01-15
    • 2016-07-31
    相关资源
    最近更新 更多