In the process of developing WPF program, in the page of writing XAML, we can see that many default namespaces in the framework use a section of URL...

Copy these websites in the browser, not all of them can be directly accessed! How are these URLs defined and why can they be used to represent namespaces?

Find definition

For example, MaterialDesignInXamlToolkit ,following code in the AssemblyInfo file of this control library:

[assembly: XmlnsPrefix("", "materialDesign")]
[assembly: XmlnsDefinition("", "MaterialDesignThemes.Wpf")]
[assembly: XmlnsDefinition("", "MaterialDesignThemes.Wpf.Transitions")]
[assembly: XmlnsDefinition("", "MaterialDesignThemes.Wpf.Converters")]

The URL contained in it is not exactly the namespace we declared when using the control, such as:


By declaring the above URL, you can directly call
Class library methods in three namespaces are amazing!

How to make your own control library also use the URL to declare

1.Create a control class library

Open the AssemblyInfo.cs file, and write the code as follows:

[assembly: XmlnsPrefix("", "ZDY")]
[assembly: XmlnsDefinition("", "ZDY.LovePlayer.Control")]

Among them:

XmlnsDefinition is the definition method of corresponding relationship between URL and namespace

XmlnsPrefix is the default prefix when defining the declaration namespace. The default prefix can be modified at will during the call without too much entanglement

2.Create a WPF test program

introduce its own control library, and try to declare in the namespace:


It can be invoked in XAML. Example code:

<ZDY:IconTextBlock Icon="Heart" Text="203208;"/>

On the understanding of namespace in the form of web address

A namespace in the form of a web address is equivalent to a namespace in the traditional form, and can also be defined in a one to many relationship

And the website is the website of the company where the developer is located, or the website of the individual...

Like The Article To View All

All Comments

Leave a Reply Cancel Reply

Tips: Your email address will not be disclosed!

If you can't see clearly,please click to change...