这是我的第一个Xamarin项目,已经遇到了一个奇怪的问题。
从MainPage.xaml开始,我想用ItemFetailViewModel作为参数来调用ItemDetailsPage。
在编译时,VS抛出“ The type or namespace name 'ItemDetailsPage' could not be found"
。没有红色下划线。
我检查了.xaml和.xaml.cs中的命名空间是否正确
MainPage.xaml.cs
namespace testapp3.Views
public partial.....
{
Method()
{
await Navigation.PushAsync(new ItemDetailsPage(new ItemDefailViewModel(item)
}
}
ItemDetailsPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="testapp3.Views.ItemDetailsPage">
</ContentPage>
ItemDetailsPage.xaml.cs
namespace testapp3.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ItemDetailsPage : ContentPage
{
ItemDetailViewModel viewModel;
public ItemDetailsPage ()
{
InitializeComponent ();
}
public ItemDetailsPage(ItemDetailViewModel item)
{
InitializeComponent();
BindingContext = this.viewModel = item;
}
}
}