Analyze the problem of the namespace of the XAML file in WPF

As we all know, the role of namespace is to distinguish the ownership of elements with the same name, for example: How do Microsoft's Button element and Apple's Button element distinguish who is who (not very appropriate example).

The namespace in XAML is also used for this purpose. Using the attribute to declare the default namespace, the namespace will be applied to the element and its children that appear. The namespace is unique, and this is easy to understand, and URI is usually used as the namespace.

WPF namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation

This represents Microsoft's namespace, which cannot be opened by a browser and is used to identify elements in XAML files.

XAML namespace: http://schemas.microsoft.com/winfx/2006/xaml

The same cannot be opened with a browser. This is to use some of XAML's own elements or attributes, which are customarily declared as the x: prefix.

These two are common namespaces for XAML files.

There is also a thing called x:Class, which can only appear in the root element of the XAML file, and can only appear in the XAML file that will be compiled into a part of the project. Loose XAML cannot be used.

At present, the problem encountered is that I want to read the contents of the XAML file, and the XAML file I wrote myself will reference other contents of the project. I encountered an error when reading: XmlNamespace is missing in the Mapping description , Assembly or ClrNamespace

So, in the XAML file, replace

clr-namespace:DiagramDesigner  改为  clr-namespace:DiagramDesigner;assembly=DiagramDesigner

After checking the usage of assembly, MSDN explains it like this:

assembly= Contains assemblies that partially or fully reference the CLR namespace. This value is usually the name of the assembly rather than the path, and does not include the extension (such as .dll or .exe). The assembly path must be created as a project reference in the project file containing the XAML to be mapped.

Analyze: It is probably through assembly to add your own program as an external reference to the XAML file to use its code.

Guess you like

Origin blog.csdn.net/kakaluote81/article/details/82222104