我在xamarin.forms中找不到要导航到的页面。我到处找,似乎只有我一个人遇到这个问题。
我有三个文件:
但是我在新的主页上总是发现一个错误(找不到)。班就在那儿,就是找不到。
public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); } void LoginButton_Clicked(object sender, EventArgs e) { bool isIdEmpty = String.IsNullOrEmpty(idEntry.Text); bool isPasswordEmpty = String.IsNullOrEmpty(passwordEntry.Text); if(isIdEmpty || isPasswordEmpty) { } else { Navigation.PushAsync(new HomePage()); } } } }
检查两个页面是否在同一个命名空间中。例如,如果 MainPage 是在 YourApp 命名空间:
MainPage
YourApp
namespace YourApp { public class MainPage { // ... Your code } }
以及 HomePage 是在 YourApp.Pages 命名空间,然后需要在 主页 以下内容:
HomePage
YourApp.Pages
主页
using YourApp.Pages; // Probably other ones here namespace YourApp { public class MainPage { // ... Your code } }
或者,可以在声明中指定完整的命名空间: Navigation.PushAsync(new YourApp.Pages.HomePage());
Navigation.PushAsync(new YourApp.Pages.HomePage());