Namespace error when I create "Resource Dictionary ..." inside a folder

1

In an empty project (test - WPF Application) I test two scenarios.

Scenario 1

  • Right click on the project
  • Add
  • Resource Dictionary ... I get the following:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:teste">
    
</ResourceDictionary> 

Scenario 2

  • Right click on the project
  • Add
  • New Folder
  • Right click on the "folder"
  • Add
  • Resource Dictionary ...

I get:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:teste.pasta">
    
</ResourceDictionary>

In this second scenario, "clr-namespace: test.folder" contains a blue wavy line that indicates the error "Undefined CLR-Namespace ..."

What's wrong here?

    
asked by anonymous 16.05.2016 / 16:32

1 answer

0

By default, Visual Studio creates the entities namespace based on the folder structure of the place where the entity is created, following the pattern [namespace padrão do projeto].[Pasta].[Subpasta] and so on.

When you create a dictionary, VS adds a reference to the namespace site using the same pattern to make it easier to use classes . However, the namespace teste.pasta is not found because it has no declared entity.

An easy way to fix it is by deleting xmlns:local="clr-namespace:teste.pasta" from the dictionary. If you intend to declare another entity in the same namespace (for example creating a class within that folder), this problem will disappear automatically, since namespace will exist. / p>     

16.08.2017 / 17:27