[英]Xamarin - type or namespace name could not be found
I am trying to used Navigation.PushAsync
to go to a new page in my Xamarin Forms application. 我正在尝试使用
Navigation.PushAsync
转到Xamarin Forms应用程序中的新页面。 I have a page called InvMachineryItem.xaml
in the same folder as the page I am currently on. 我在与当前所在页面相同的文件夹中有一个名为
InvMachineryItem.xaml
的页面。
In my current page I have a list. 在当前页面上,我有一个列表。 When the list is clicked, the new page should open.
单击列表后,将打开新页面。
Here is my code: 这是我的代码:
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 problem is I am receiving an error: 问题是我收到一个错误:
The type or namespace name "InvMachineryItem' could not be found (are you missing a using directive or an assembly reference?)
I am confused because they are in the same folder, and I am also implementing a using
statement as well. 我很困惑,因为它们位于同一文件夹中,而且我也正在实现
using
语句。
For additional context, here is the InvMachineryItem.xaml.cs class 对于其他上下文,这是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));
}
}
}
Currently, InvMachineryItem
lives on myCoolApp.Views.Inventory
namespace, so the fix is you should change the using statement to using myCoolApp.Views.Inventory
. 当前,
InvMachineryItem
位于myCoolApp.Views.Inventory
命名空间中,因此解决方法是您应将using语句更改为using myCoolApp.Views.Inventory
。
Second fix, just in case you want your InvMachineryItem to live inside myCoolApp.Views
, you need to change the namespace to myCoolApp.Views.Inventory
and also update the namespace on your XAML. 第二个解决方法,以防万一您希望InvMachineryItem驻留在
myCoolApp.Views
,则需要将名称空间更改为myCoolApp.Views.Inventory
并更新XAML上的名称空间。
The first fix is much easier, you should use it. 第一个修复程序要容易得多,您应该使用它。
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.