在 Visual Studio 解决方案中重新链接 Xaml 和代码隐藏 [英] Re-Link Xaml and Code Behind in Visual Studio Solution

查看:28
本文介绍了在 Visual Studio 解决方案中重新链接 Xaml 和代码隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 XAML 文件说 SomePage.xaml.

I have XAML file say SomePage.xaml.

我犯了一个错误,将它的类背后的代码从 SomePage 重构为 CardsPage 类.

I was making a mistake by refactored it's code behind class from SomePage to CardsPage class.

现在 XAML 文件不再与背后的代码链接.

Now XAML file doesn't link with the code behind anymore.

如何将这些文件重新链接在一起?

How to link these files together again?

推荐答案

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

If you open the project file that includes your CardsPage, you can link them back together again.

你应该有两个部分,一个应该是这样的:

You should have 2 sections in there, one should be like this:

<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.

The DependentUpon is important, it will nest the file in the IDE below the xaml.
Note: In your screenshot, the CardsPage looks like it was renamed to CardsPage.cs, I would make sure that you rename it back to CardsPage.xaml.cs.

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

Hope that helps, I sadly don't know any other way than fiddling in the project file to make it work again.

这篇关于在 Visual Studio 解决方案中重新链接 Xaml 和代码隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆