2013-09-27 21 views
2

注意Telerik命名空間。這不是你所期望的clr-namespace:Telerik;assembly=Telerik。他們是如何做到的呢?如何爲XAML創建我自己的(非CLR!)XML命名空間?

<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> 
+1

[這是否有幫助?](http://www.codeproject.com/Articles/111911/A-Guide-to-Cleaner-XAML-with-Custom-Namespaces-and) –

+0

發佈它作爲答案。 –

回答

3

您可以使用XmlnsDefinition屬性將一個或多個CLR名稱空間映射到URI;例如:

[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")] 

您還可以使用XmlnsPrefix屬性的默認前綴爲您的命名空間相關聯:

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

請注意,此屬性僅用作編輯工具的建議。

+0

使用基於URI的模式的優點是什麼?對不起,如果我脫離了原來的話題。 – Lance

+0

@ LawrenceA.Contreras,它允許您爲幾個CLR命名空間聲明單個XML命名空間。如果您知道給定的組件位於庫中,則不需要記住它在哪個CLR名稱空間中聲明。 –

+0

我明白了。謝謝托馬斯。 – Lance

相關問題