How to define a web address as a namespace for your own WPF Control Library
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("http://materialdesigninxaml.net/winfx/xaml/themes", "materialDesign")]
[assembly: XmlnsDefinition("http://materialdesigninxaml.net/winfx/xaml/themes", "MaterialDesignThemes.Wpf")]
[assembly: XmlnsDefinition("http://materialdesigninxaml.net/winfx/xaml/themes", "MaterialDesignThemes.Wpf.Transitions")]
[assembly: XmlnsDefinition("http://materialdesigninxaml.net/winfx/xaml/themes", "MaterialDesignThemes.Wpf.Converters")]
The URL contained in it is not exactly the namespace we declared when using the control, such as:
xmlns:MaterialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
By declaring the above URL, you can directly call
MaterialDesignThemes.Wpf
MaterialDesignThemes.Wpf.Transitions
MaterialDesignThemes.Wpf.Converters
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("http://www.zdyla.com/coding", "ZDY")]
[assembly: XmlnsDefinition("http://www.zdyla.com/coding", "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:
xmlns:ZDY="http://www.zdyla.com/coding"
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...
- Link : https://www.zdyla.com/en/post/how-to-define-a-web-address-as-a-namespace-for-your-own-wpf-control-library.html
- Copyright Notice : Unless otherwise stated, please contact the author for authorization and indicate the source!