Xamarin - 无法找到类型或命名空间名称

时间:2017-05-30 01:54:11

标签: c# xamarin xamarin.forms

我正在尝试使用Navigation.PushAsync转到我的Xamarin Forms应用程序中的新页面。我在与我当前所在页面相同的文件夹中有一个名为InvMachineryItem.xaml的页面。

在我当前的页面中,我有一个列表。单击列表后,应打开新页面。

这是我的代码:

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

1 个答案:

答案 0 :(得分:1)

目前,InvMachineryItem位于myCoolApp.Views.Inventory命名空间,因此修复时应将using语句更改为using myCoolApp.Views.Inventory

第二个修复,如果您希望InvMachineryItem位于myCoolApp.Views内,则需要将命名空间更改为myCoolApp.Views.Inventory并更新XAML上的命名空间。

第一个修复更容易,你应该使用它。

希望它有所帮助!

相关问题