[英]InitializeComponent does not exist in the current context error
I'm getting this error on my Xamarin.Forms project whenever I try to create a Page with XAML+CS. 每当我尝试使用XAML + CS创建Page时,我的Xamarin.Forms项目都会出现此错误。
The namespace on the file corresponds: 文件上的名称空间对应于:
And I've set the build action of the XAML Page to EmbeddedResource
with the Custom Tool MSBuild:UpdateDesignTimeXaml
. 并且我已使用自定义工具MSBuild:UpdateDesignTimeXaml
将XAML页面的构建操作设置为EmbeddedResource
。
I checked the .csproj and it sets correctly the build action: 我检查了.csproj,它正确设置了构建操作:
<ItemGroup>
<EmbeddedResource Include="AppCore\Pages\SettingsPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
And: 和:
<Compile Include="AppCore\Pages\SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
Cleaning the solution and deleting the obj/bin folders didn't help and neither reinstalling the packages via update-package -project Travlendar.Core -reinstall
. 清理解决方案并删除obj / bin文件夹无济于事,也没有通过update-package -project Travlendar.Core -reinstall
重新安装软件包。
This is SettingsPage: 这是SettingsPage:
using Travlendar.Core.AppCore.ViewModels;
using Xamarin.Forms;
namespace Travlendar.Core.AppCore.Pages
{
public partial class SettingsPage : ContentPage
{
public SettingsPage (INavigation navigation)
{
InitializeComponent ();
BindingContext = new SettingsViewModel (this, navigation);
}
}
}
Found the solution, I had to delete the packages
folder in the solution. 找到解决方案后,我不得不删除解决方案中的packages
文件夹。
Then cleaning/re-building the solution and everything is working back. 然后清洗/重新构建解决方案,一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.