Ansis Māliņš
Ansis Māliņš

Reputation: 1712

How do I create my own (non-CLR!) XML namespace for XAML?

Notice the Telerik namespace. It's not clr-namespace:Telerik;assembly=Telerik as you would expect. How did they do it?

<UserControl x:Class="Sandbox.MyUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
    </Grid>
</UserControl>

Upvotes: 2

Views: 464

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292445

You can map one or more CLR namespaces to an URI, using the XmlnsDefinition attribute; for instance:

[assembly: XmlnsDefinition("http://www.yourdomain.com/schema", "MyProject.Foo")]
[assembly: XmlnsDefinition("http://www.yourdomain.com/schema", "MyProject.Bar")]
[assembly: XmlnsDefinition("http://www.yourdomain.com/schema", "MyProject.Baz")]

You can also use the XmlnsPrefix attribute to associate a default prefix for your namespace:

[assembly: XmlnsPrefix("http://www.yourdomain.com/schema/", "foo")]

Note that this attribute is only used as a suggestion for editing tools.

Upvotes: 3

Related Questions