2017-05-30 155 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

相关问题