【问题标题】:Cant find page in Xamarin.forms在 Xamarin.forms 中找不到页面
【发布时间】:2018-07-12 07:32:06
【问题描述】:

我在 Xamarin.forms 中找不到要导航到的页面。我一直在到处寻找,看来我是唯一遇到此问题的人。

我有这 3 个文件:

但我在新主页上不断收到错误消息(找不到)。班级就在那儿,只是找不到..

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

【问题讨论】:

  • 它是否在另一个命名空间中?
  • 我们需要看看HomePage是什么样子的

标签: visual-studio xaml xamarin xamarin.forms


【解决方案1】:

检查两个页面是否在同一个命名空间中。例如,如果 MainPageYourApp 命名空间中:

namespace YourApp
{
    public class MainPage
    {
        // ... Your code
    }
}

HomePage 位于YourApp.Pages 命名空间中,那么您需要在MainPage 的顶部添加一条using 语句:

using YourApp.Pages;
// Probably other ones here

namespace YourApp
{
    public class MainPage
    {
        // ... Your code
    }
}

或者,您可以在声明中指定完整的命名空间:Navigation.PushAsync(new YourApp.Pages.HomePage());

【讨论】:

  • 你是个天才!非常感谢!现在 xaml.cs 页面无法识别 InitializeComponent 方法。我累了
  • 如果您更改了命名空间,但请确保在页面的 XAML 部分中也进行了更改
  • 啊,是的,这只是一个构建/保存问题,已自行修复。非常感谢好心的陌生人!
  • 完全没有问题,别忘了接受它作为答案!
猜你喜欢
  • 2014-02-15
  • 2021-05-17
  • 2015-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多