简体   繁体   English

初始化组件不存在且 Xamarin Forms Visual Studio 中未添加 xaml 文件

[英]Initialize Component does not exist and xaml file not added in Xamarin Forms Visual Studio

I just started learning Xamarin a few days ago.我几天前才开始学习 Xamarin。 I am now developing an Application using Xamarin.Forms.我现在正在使用 Xamarin.Forms 开发应用程序。 Now I am having an issue with adding new xaml view to my project.现在我在向我的项目添加新的 xaml 视图时遇到问题。 I am now creating a new view and when user click on, a button from the different page, user will be redirected to that view.我现在正在创建一个新视图,当用户单击来自不同页面的按钮时,用户将被重定向到该视图。 It is giving me error while I add a new view.添加新视图时,它给了我错误。

I right click on the Views folder and add new xaml content page like this我右键单击 Views 文件夹并添加新的 xaml 内容页面,如下所示

在此处输入图片说明

Then the xaml file is not added.然后不添加 xaml 文件。 Please compare my newly added HelloPage and AboutPage below.请在下面比较我新添加的 HelloPage 和 AboutPage。

在此处输入图片说明

Then the class file is throwing following error.然后类文件抛出以下错误。

在此处输入图片说明

But when I open the file explorer, I can see the XAML file as below.但是当我打开文件资源管理器时,我可以看到如下的 XAML 文件。

在此处输入图片说明

Is that the bug with Visual Studio?这是 Visual Studio 的错误吗? I am using VS 2017. How can I fix the issue?我正在使用 VS 2017。我该如何解决这个问题? I tried on many solutions like this - Xamarin Forms InitializeComponent does not exist , but it is not helping.我尝试了很多这样的解决方案 - Xamarin Forms InitializeComponent does not exist ,但它没有帮助。 I believe that it is throwing "Initialize Component does not exist" error because XAML file is not properly.我相信它会抛出“初始化组件不存在”错误,因为 XAML 文件不正确。 How can I fix it?我该如何解决?

When I build the project, it shows me this error.当我构建项目时,它显示了这个错误。

在此处输入图片说明

In my case, it is "HelloPage.xaml" not the "NewPage.xaml" as in the screenshot.就我而言,它是“HelloPage.xaml”而不是屏幕截图中的“NewPage.xaml”。

You should clean, then rebuild solution.您应该清洁,然后重建解决方案。 Do it a couple of times, if error continues restart visual studio 2017.做几次,如果错误继续重启visual studio 2017。

Sometimes you have to reset visual studio有时您必须重置visual studio

I had the same problem when I created a new project.当我创建一个新项目时,我遇到了同样的问题。 VisualStudio 2017 had named the main page xaml file MainPage.xaml. VisualStudio 2017 已将主页 xaml 文件命名为 MainPage.xaml。 I renamed MainPage.xaml,MainPage.xaml.cs to something else.我将 MainPage.xaml,MainPage.xaml.cs 重命名为其他内容。 This is when I started getting the error.这是我开始收到错误的时候。 I had changed all the references except for one in the xaml file.除了 xaml 文件中的一个之外,我已经更改了所有引用。 In the ContentPage tag, I had forgotten to change the attribute, x:Class="App.MainPage" to x:Class="App.NewPage".在 ContentPage 标记中,我忘记将属性 x:Class="App.MainPage" 更改为 x:Class="App.NewPage"。

Check your ContentPage tag in your xaml file.检查您的 xaml 文件中的 ContentPage 标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM