Error in namespace when creating "Resource Dictionary ..." inside a folder

Asked

Viewed 55 times

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 (folder)
  • Right click on the "folder"
  • Add
  • Resource Dictionary ...

Obtenho:

<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:teste.pasta" contains a blue wavy that indicates the error "Undefined CLR-Namespace. ..."

What is wrong here?

1 answer

0

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

When you create a dictionary, the VS adds a reference to namespace "place" using the same standard, to facilitate the use of classes of that namespace. Meanwhile, the namespace teste.pasta is not found as it has no declared entity.

An easy way to fix is to erase the xmlns:local="clr-namespace:teste.pasta" dictionary. If you intend to declare another entity in that same namespace (for example creating a class within that folder), this problem will automatically disappear once the namespace will come into existence.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.