1

I just started learning Xamarin a few days ago. I am now developing an Application using Xamarin.Forms. Now I am having an issue with adding new xaml view to my project. 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

enter image description here

Then the xaml file is not added. Please compare my newly added HelloPage and AboutPage below.

enter image description here

Then the class file is throwing following error.

enter image description here

But when I open the file explorer, I can see the XAML file as below.

enter image description here

Is that the bug with Visual Studio? I am using VS 2017. How can I fix the issue? I tried on many solutions like this - Xamarin Forms InitializeComponent does not exist, but it is not helping. I believe that it is throwing "Initialize Component does not exist" error because XAML file is not properly. How can I fix it?

When I build the project, it shows me this error.

enter image description here

In my case, it is "HelloPage.xaml" not the "NewPage.xaml" as in the screenshot.

6
  • I just updated the question. it is because xaml file is not found. Mar 7, 2018 at 11:42
  • What version of VS are you using? Also, it looks like as a workaround you'll have to manually add in your xaml page to the project and then set your page xaml.cs dependent upon your xaml in your cs project. As to why VS isn't doing that for you, which it usually does, when you add a new page I have no idea. Mar 7, 2018 at 13:57
  • I am using Visual Studio 2017 community. Is there a way to fix that issue please? I have been trying all possible solutions and none on them was working. Mar 7, 2018 at 15:24
  • If you create a brand new empty project does the same thing happen? If it does you might want to uninstall VS and reinstall or check for any updates. Mar 7, 2018 at 15:55
  • Yes. It happens all the time Mar 7, 2018 at 15:58

2 Answers 2

0

You should clean, then rebuild solution. Do it a couple of times, if error continues restart visual studio 2017.

Sometimes you have to reset visual studio

0

I had the same problem when I created a new project. VisualStudio 2017 had named the main page xaml file MainPage.xaml. I renamed MainPage.xaml,MainPage.xaml.cs to something else. This is when I started getting the error. I had changed all the references except for one in the xaml file. In the ContentPage tag, I had forgotten to change the attribute, x:Class="App.MainPage" to x:Class="App.NewPage".

Check your ContentPage tag in your xaml file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.