Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New WPF Custom Control Library Name does not exist in Namespace

I am new to WPF and I am trying to resolve an error. I am trying to build a custom control library where I can make my own control objects. When I go to File > New Project > WPF Custom Control Library > [Enter name] > Save, then instant error:

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

I did not edit any code but immediately an error. For reference, the error is inside 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>

I am using Visual Studio 12 and .NET 4. Any ideas?

like image 391
user654628 Avatar asked Sep 24 '12 16:09

user654628


1 Answers

This is an IntelliSense error, not a build error, so it should not affect building the project. To resolve this error, either

  • build the project, or
  • edit the document (e.g. by removing a > from a tag, then adding it back).

When you open the document, the XAML designer loads in the background to provide IntelliSense information. It loads information for unbuilt types (i.e., types defined in the current Solution but which have not yet been built into an assembly) asynchronously, and often this process completes after the designer has completed the initial parse of the document.

Building the project will cause the unbuilt types to be built (thus resolving the issue), and making a material edit to the document will cause the designer to reparse the document with the newly available type information (ideally, the document should be reparsed when the unbuilt type information becomes available).

like image 139
James McNellis Avatar answered Sep 28 '22 05:09

James McNellis