简体   繁体   中英

Forms Xaml Page missing in Visual Studio 2017 Xamarin

All the tutorials and web pages talk about using Project|Add New Item and adding a new "Forms Xaml Page". But whenever I install Xamarin and Visual Studio 2015, I just get the "Forms ContentPage" and "Forms ContentView" which just generate a C# file, no Xaml.

I have tried this and it didnt work.

And I've also tried reinstalling Visual Studio. Does anyone have a clue what to do?

The real problem is that I want to keep the Xaml with the code-behind file together, like 这个

I just did a clean install of Visual Studio 2017 and the "Forms Content Page Xaml" showed up in Add New Item dialog. Which items you chose when installing the Xamarin for Visual Studio pack? Compare with the ones I've selected. Maybe something was left unchecked?

Also, if you want to keep the Xaml file together with the code-behind file, there's a way to do it by editing the YourProjectName.projitems inside your project folder. To find it, right-click the your main project and open its folder in the Windows Explorer, and then use a file editor to edit the .projitems file. Search for the Compile tag for the .cs files you want and add the DependentUpon tag inside it, just like in the example below:

<Compile Include="$(MSBuildThisFileDirectory)YourFile.xaml.cs">
  <DependentUpon>YourFile.xaml</DependentUpon>
</Compile>

After doing this, unload and reload your project. Unfortunatelly I've had to do this procedure to all the new Xaml files I've created on my projects.

I think you can use the content page, it has the .xaml extension and comes with the code behind. They just change the name of the template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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