c# - 在 Visual Studio 解决方案中重新链接 Xaml 和代码隐藏

标签 c# xaml visual-studio-2017

我有 XAML 文件说 SomePage.xaml .

我通过重构它的代码在来自 SomePage 的类背后犯了一个错误至 CardsPage类(class)。

现在 XAML 文件不再与后面的代码链接。

Separate File

如何将这些文件再次链接在一起?

最佳答案

如果您打开包含 CardsPage 的项目文件,您可以将它们重新链接在一起。

你应该在那里有 2 个部分,一个应该是这样的:

<Page Include="CardsPage.xaml">
  <Generator>MSBuild:Compile</Generator>
  <SubType>Designer</SubType>
</Page>

另一部分应如下所示:
<Compile Include="CardsPage.xaml.cs">
  <DependentUpon>CardsPage.xaml</DependentUpon>
</Compile>

DependentUpon 很重要,它会将文件嵌套在 IDE 中的 xaml 下方。
备注 :在您的屏幕截图中,CardsPage 看起来像是重命名为 CardsPage.cs,我会确保您将其重命名回 CardsPage.xaml.cs。

希望有所帮助,遗憾的是,除了摆弄项目文件以使其再次工作之外,我不知道其他任何方法。

关于c# - 在 Visual Studio 解决方案中重新链接 Xaml 和代码隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44342724/

相关文章:

c# - 在 C# 中返回 IList<T> 与数组?

c# - .NET Microsoft.AspNetCore.Http.Extensions UriHelper.GetDisplayUrl 返回无效的 URI

c# - 将变量从控制台传递到 vbs 到 Excel 宏

c# - XAML 在不改变颜色的情况下改变背景不透明度

c# - Visual Studio 2017 更新到 15.8.1/15.8.2 后的 Xamarin Android 应用项目构建问题

c++ - 在 Visual Studio 中使用 decltype 派生的返回类型专门化模板

c# - 将值添加到字符串会导致添加额外的空格

c# - Textblock DataTriggers 未触发

c# - 无法覆盖 WPF 中 app.xaml 的按钮样式

visual-studio-2017 - Visual Studio 2017 - 错误 : Unable to update the dependencies of the project (setup & deployment)