2017-05-30 157 views
0

我正在嘗試使用Navigation.PushAsync轉到我的Xamarin Forms應用程序中的新頁面。我在與當前頁面相同的文件夾中有一個名爲InvMachineryItem.xaml的頁面。Xamarin - 無法找到類型或名稱空間名稱

在我目前的頁面我有一個列表。點擊列表時,新頁面應該打開。

這裏是我的代碼:

 using myCoolApp.Views; //folder with the pages in it 

    async void navigateView() 
    { 
     Page page = new InvMachineryItem(); 
     await Navigation.PushAsync(page); 
    } 

    void machineList_ItemSelected(object sender, SelectedItemChangedEventArgs e) 
    { 
      navigateView(); 
      //...more stuff 
    } 

問題是我收到的錯誤:

The type or namespace name "InvMachineryItem' could not be found (are you missing a using directive or an assembly reference?) 

我很困惑,因爲他們是在同一個文件夾中,而我也實現using聲明。

有關其他方面,這裏是InvMachineryItem.xaml.cs類

namespace myCoolApp.Views.Inventory 
{ 
    [XamlCompilation(XamlCompilationOptions.Compile)] 
    public partial class InvMachineryItem : ContentPage 
    { 
     List<ListTemplate> viewButtons = new List<ListTemplate>(); 
     SessionData viewModel; 
     public InvMachineryItem() 
     { 
      InitializeComponent(); 
      viewModel = ViewModelLocator.Session; 
      NavigationPage.SetHasNavigationBar(this, false); 

      viewButtons.Add(new ListTemplate("view.png", "View", true, true)); 
      viewButtons.Add(new ListTemplate("edit.png", "Edit", true, true)); 
      viewButtons.Add(new ListTemplate("AddMaintenance.png", "Add Maintenance", true, true)); 
     } 
    } 
} 
+0

你還可以分享InvMachineryItem的類嗎?謝謝! – mindOfAi

+0

當然,有一刻 –

+0

InvMachineryItem在myCoolApp.Views.Inventory中,您應該將using語句添加到其他文件的停止處,或者將它們更改爲使它們都在相同的命名空間中 – Jason

回答

1

目前,InvMachineryItem生活在myCoolApp.Views.Inventory命名空間,因此修復是你應該using語句改爲using myCoolApp.Views.Inventory

第二次修復,爲了防止您的InvMachineryItem生存在myCoolApp.Views之內,您需要將名稱空間更改爲myCoolApp.Views.Inventory並更新XAML上的名稱空間。

第一次修復更容易,您應該使用它。

希望它有幫助!

+1

謝謝!我很愚蠢地認爲,如果我包含了它將包含的父文件夾。當計時器結束時,我會在1分鐘內將您的答覆標記爲答案! –

+0

太棒了!祝你的發展順利! :) – mindOfAi

相關問題