简体   繁体   English

Visual Studio 2017 Xamarin中缺少Forms Xaml页面

[英]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". 所有教程和网页都讨论如何使用Project | Add New Item以及添加新的“ 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. 但是,每当我安装Xamarin和Visual Studio 2015时,我只会得到“ Forms ContentPage”和“ Forms ContentView”,它们只会生成一个C#文件,而不是Xaml。

I have tried this and it didnt work. 我已经尝试过 ,但没有成功。

And I've also tried reinstalling Visual Studio. 而且我还尝试过重新安装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 真正的问题是我想将带有代码隐藏文件的Xaml放在一起,例如 这个

I just did a clean install of Visual Studio 2017 and the "Forms Content Page Xaml" showed up in Add New Item dialog. 我只是对Visual Studio 2017进行了全新安装,“添加新项”对话框中显示了“表单内容页面Xaml”。 Which items you chose when installing the Xamarin for Visual Studio pack? 在安装Xamarin for Visual Studio包时选择了哪些项目? 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. 另外,如果要将Xaml文件与代码隐藏文件保存在一起,则可以通过编辑项目文件夹中的YourProjectName.projitems来实现。 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. 要找到它,请右键单击您的主项目,然后在Windows资源管理器中打开其文件夹,然后使用文件编辑器来编辑.projitems文件。 Search for the Compile tag for the .cs files you want and add the DependentUpon tag inside it, just like in the example below: 搜索所需的.cs文件的Compile标签,并在其中添加DependentUpon标签,如以下示例所示:

<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. 不幸的是,我必须对在项目上创建的所有新Xaml文件执行此过程。

I think you can use the content page, it has the .xaml extension and comes with the code behind. 我认为您可以使用内容页面,该页面具有.xaml扩展名,并附带代码。 They just change the name of the template. 他们只是更改模板的名称。

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

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