【问题标题】:create X.xaml and X.xaml.cs files vs should understand they are xaml and code behind创建 X.xaml 和 X.xaml.cs 文件 vs 应该了解它们是 xaml 和代码背后
【发布时间】:2012-05-01 12:02:43
【问题描述】:

我创建了两个文件NodeControl.xamlNodeControl.xaml.cs

在xaml文件中写了x:Class="TreeTest.NodeControl.NodeControl"

在cs文件中我写了partial,在构造函数中我调用InitializeComponent();

它们工作正常,但 VS2010 不明白它们是 xaml 和代码背后

我是不是做错了什么?

【问题讨论】:

  • 我建议不要用相同的名称命名子命名空间和类名,因为如果没有完全限定命名空间(使用 TreeTest.NodeControl ; 不起作用)。

标签: c# .net wpf visual-studio-2010


【解决方案1】:

这是因为 Visual Studio 不知道它们是关联的。拥有 .xaml 和 .xaml.cs 只是一个命名约定。在项目文件中,您需要通过以下方式强制执行关系:

<Compile Include="NodeControl.xaml.cs">
  <DependentUpon>NodeControl.xaml</DependentUpon>
</Compile>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    相关资源
    最近更新 更多