2016-06-25 32 views
0

好日子每個人。我正在做一個Xamarin.Forms便攜式應用程序,其中我創建了兩個視圖MainPageMain.xamlSecondPage.xaml在App.cs,我已經把我的根頁面MainPageMain但我想將其更改爲SecondPage無法找到類型或名稱空間名稱'PROJECTNAME'(您是否缺少使用指令或程序集引用?

每次我改變了它,出現此錯誤:

無法找到類型或命名空間名稱'PROJECTNAME'(您是否缺少using指令或程序集引用?

enter image description here

背後有什麼原因呢?如果您需要更多代碼,請告訴我。

這是我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(); 
     } 
    } 
} 

App.cs

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

回答

1

SecondPage類可能位於命名空間中,需要使用using語句添加。這可能是問題的原因。要進一步檢查,您可以發佈更多的代碼。

+0

當然可以。但是我需要發佈什麼代碼? –

+0

您應該檢查'SecondPage'類在您的代碼中的位置。我想你會得到你的答案。另外,請檢查'SecondPage'類的'xaml'表單。 – vivek

+0

我編輯了我的帖子,先生。 –

0

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

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

這是爲我工作。

相關問題