找不到类型或命名空间名称“MainPage”(是否缺少 using 指令或程序集引用?

本文关键字:using 指令 程序集 引用 是否 命名空间 类型 找不到 MainPage | 更新日期: 2023-09-27 18:35:31

我有一个Windows Mobile c# xaml的应用程序。 当我构建解决方案时,它在页面 App.xaml.cs 中给了我此错误:

错误 2 找不到类型或命名空间名称"MainPage"(是否缺少 using 指令或程序集引用? c:''users''user''documents''Visual Studio 2013''projects''app5''app5''app5.shared''app.xaml.cs 105 48 App5.WindowsPhone

App.xaml.cs 中的代码是:

   if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
            {
                throw new Exception("Failed to create initial page");
            }

当主页被标记为错误时。 可能是什么问题?

更新:App 类和 MainPage 类位于同一命名空间 (App5) 中。类在 MainPage.xaml.cs 中的同一文件夹中定义。

找不到类型或命名空间名称“MainPage”(是否缺少 using 指令或程序集引用?

检查代码隐藏和 XAML 文件中类名的完整路径。他们必须匹配!

此外,请确保您的 app.xaml 文件引用了主页的正确 URL。