In a WPF application, you can create XmlnsDefinitions to map multiple namespaces from another assembly into one reference .
You can take advantage of that to map your own namespaces to the Microsoft default XmlnsDefinition, for example:
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "MyLibrary.MyControls")]
This way, you don't even need to add a reference to your namespace in the XAML file, because they are already mapped to the default "xmlns".
So, if I had a control called "MyControl", I can use it like this (without any namespaces or prefixes):
<MyControl />
My question is: Can I merge the default Microsoft namespaces into a single one?
For example: I want to get rid of the "xmlns:x" namespace by merging it into "xmlns". I would have to reference all the namespaces in "http://schemas.microsoft.com/winfx/2006/xaml" to "http://schemas.microsoft.com/winfx/2006/xaml/presentation".
Like this:
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System...")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System...")]
...
So I can turn this:
<Window x:Class="MyProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
Into this:
<Window Class="MyProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>
UserControl
intoSystem.Windows.Controls
. And it does not work for me:[assembly: System.Windows.Markup.XmlnsDefinition( "http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Controls" )]
Looks like designer is seeing my class, but compiler not. Error:The tag 'ContentViewer' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'
– Denis535