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

标签 wpf visual-studio intellisense visual-studio-2012 xaml-designer

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

The name "CustomControl1" does not exist in the namespace "clr-namespace:ProjectName"

我没有编辑任何代码,但立即出现错误。作为引用,错误在 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>

我正在使用 Visual Studio 12 和 .NET 4。有什么想法吗?

最佳答案

这是 IntelliSense 错误,而不是构建错误,因此它不会影响构建项目。要解决此错误,要么

  • 构建项目,或
  • 编辑文档(例如,从标签中删除 >,然后将其添加回来)。

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

    构建项目将导致构建未构建的类型(从而解决问题),对文档进行 Material 编辑将导致设计人员使用新可用的类型信息重新解析文档(理想情况下,应重新解析文档)未构建的类型信息变得可用)。

    关于wpf - 命名空间中不存在新的 WPF 自定义控件库名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12569558/

    相关文章:

    .net - 数据触发器未触发

    visual-studio - visual studio 2012 快捷方式实现界面

    c++ - MSVS C++ 2012 : how to disable compiling-while-editting

    .net - 确定相对于目标的弹出位置

    c# - 单击 ComboBox 的 TextBox 部分

    visual-studio - TF400324 : Team Foundation services are not available from server <Server/CollectionName> in Visual Studio 2012

    Git for Windows 停止工作 - VS Team Services

    php - 我怎样才能在 PHP/Eclipse 中获得关于在 foreach 循环中从数组中拉出的自定义对象的智能感知?

    ember.js - 用于 Ember 注入(inject)服务的 Intellisense

    wpf - 如何找出应用于控件的样式?