【问题标题】:InitializeComponent does not exist in the current context error当前上下文中不存在 InitializeComponent 错误
【发布时间】:2018-06-06 01:07:04
【问题描述】:

每当我尝试使用 XAML+CS 创建页面时,我的 Xamarin.Forms 项目都会出现此错误。

文件上的命名空间对应:

我已使用自定义工具 MSBuild:UpdateDesignTimeXaml 将 XAML 页面的构建操作设置为 EmbeddedResource
我检查了 .csproj 并正确设置了构建操作:

  <ItemGroup>
    <EmbeddedResource Include="AppCore\Pages\SettingsPage.xaml">
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
      <SubType>Designer</SubType>
    </EmbeddedResource>
  </ItemGroup>

还有:

<Compile Include="AppCore\Pages\SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>

清理解决方案并删除 obj/bin 文件夹没有帮助,也没有通过 update-package -project Travlendar.Core -reinstall 重新安装软件包。

这是设置页面:

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);
        }
    }
}

【问题讨论】:

  • 您的SettingsPage.xaml.cs 包含什么内容?
  • 在构建之前尝试关闭 settingspage.xaml.cs。不知道为什么它会有所帮助,但确实如此。
  • @SushiHangover 将代码添加到问题中,但没有什么特别之处..
  • @KenTucker 行为与以前相同..

标签: c# .net xaml xamarin xamarin.forms


【解决方案1】:

找到解决方案,我不得不删除解决方案中的packages 文件夹。
然后清理/重新构建解决方案,一切都恢复正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-19
    • 2016-06-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多