我正在尝试使用 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));
}
}
}
当前, InvMachineryItem
属于myCoolApp.Views.Inventory
名称空间,因此修复程序是您应该将使用语句更改为 using myCoolApp.Views.Inventory
。
第二修复程序,以防万一您希望您的InvmachineryItem生活在myCoolApp.Views
中,需要将名称空间更改为myCoolApp.Views.Inventory
,并在XAML上更新命名空间。
第一个修复要容易得多,您应该使用它。
希望它有帮助!