繁体   English   中英

找不到类型或名称空间名称“ PROJECTNAME”(您是否缺少using指令或程序集引用?

[英]The type or namespace name 'PROJECTNAME' could not be found (are you missing a using directive or an assembly reference?

今天是个好日子。 我目前在做,我已经创建了两个视图,即MainPageMain.xamlSecondPage.xaml一个Xamarin.Forms便携式应用。 在App.cs中,我已将根页面设置为MainPageMain,但我想将其更改为SecondPage

每次更改它时,都会出现此错误:

找不到类型或名称空间名称“ PROJECTNAME”(您是否缺少using指令或程序集引用?

在此处输入图片说明

这是什么原因呢? 如果您需要更多代码,请告诉我。

这是我的SecondPage.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="XamarinFormsDemo.Views.SecondPage"
         BackgroundColor="Teal">

  <Label Text="Sample Here!" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>

这是我的SecondPage.xaml.cs代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using XamarinFormsDemo.Views;

namespace XamarinFormsDemo.Views
    {
        public partial class SecondPage : ContentPage
        {
        public SecondPage()
        {
            InitializeComponent();
        }
    }
}

应用程式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xamarin.Forms;

namespace XamarinFormsDemo
{
    public class App : Application
    {
        public App()
        {
            // The root page of your application
            MainPage = new NavigationPage(new SecondPage());


        }

        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
        }
    }
}

SecondPage类可能在名称空间中,您需要通过using语句添加该名称空间。 这可能是问题的原因。 要进一步检查,您可以发布更多代码。

您需要在secondpage.xaml.cs中添加InitializeComponent()

private void InitializeComponent()
        {
            this.LoadFromXaml(typeof(MainPage));
        }

这对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM