命名空间中不存在新的WPF自定义控件库名称

use*_*628 11 wpf intellisense visual-studio xaml-designer visual-studio-2012

我是WPF的新手,我正在尝试解决错误.我正在尝试构建一个自定义控件库,我可以在其中创建自己的控件对象.当我转到文件>新建项目> WPF自定义控件库> [输入名称]>保存,然后即时错误:

The name "CustomControl1" does not exist in the namespace "clr-namespace:ProjectName"
Run Code Online (Sandbox Code Playgroud)

我没有编辑任何代码,但立即出错.作为参考,错误在Generic.xaml中.

<ResourceDictionary
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:local="clr-namespace:ProjectName">
       <Style TargetType="{x:Type local:CustomControl1}">  //<--Fails here
           <Setter Property="Template">
               <Setter.Value>
                   <ControlTemplate TargetType="{x:Type local:CustomControl1}">  // Fails here as well
                       <Border Background="{TemplateBinding Background}"
                               BorderBrush="{TemplateBinding BorderBrush}"
                               BorderThickness="{TemplateBinding BorderThickness}">

                       </Border>
                   </ControlTemplate>
               </Setter.Value>
            </Setter>
        </Style>
    </ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

我正在使用Visual Studio 12和.NET 4.任何想法?

Jam*_*lis 11

这是一个IntelliSense错误,而不是构建错误,因此不应影响构建项目.要解决此错误,请执行此操作

  • 建立项目,或
  • 编辑文档(例如,通过>从标记中删除,然后将其添加回来).

打开文档时,XAML设计器会在后台加载以提供IntelliSense信息.它以异步方式加载未构建类型的信息(即,当前解决方案中定义但尚未构建到程序集中的类型),并且通常在设计者完成文档的初始解析后此过程完成.

构建项目将导致构建未构建的类型(从而解决问题),并对文档进行材质编辑将导致设计者使用新可用的类型信息重新分析文档(理想情况下,文档应在未建立的类型信息变得可用).


dba*_*dba 5

根据James McNellis的回答,就我而言,我必须注释掉导致错误的XAML部分(由于错误不允许重建),然后关闭文件本身,因此无法在VS中打开文件,那么我可以制作成功。然后,我取消了XAML部分的注释,而VS能够找到本地类...以防万一,有人会偶然发现这一点。适用于Windows桌面的Visual Studio 2012 Express ... BR,

丹尼尔