xml - 如何为 XAML 创建我自己的(非 CLR!)XML 命名空间?

标签 xml wpf xaml

注意 Telerik 命名空间。这不是clr-namespace:Telerik;assembly=Telerik正如你所期望的那样。他们是怎么做到的?

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

最佳答案

您可以使用 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")]

请注意,此属性仅用作编辑工具的建议。

关于xml - 如何为 XAML 创建我自己的(非 CLR!)XML 命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19048288/

相关文章:

java - Android 应用程序无法连接到互联网

xaml - Xamarin 将父 BindingContext 值传递给转换器

c++ - 如何在 Canvas 上画一个径向渐变的圆?

c# - Windows Phone 项目不支持 VideoBrush

c# - 从 Linq 查询调用方法

c# - 引用类型 DependencyProperty 的 WPF 样式

c# - 具有多个 TextBlock 的 XAML 样式按钮

java - 使用 Java 读取 XML 中的 XML

c# - DateTime.Now 没有小数秒

java - JPA 如何知道如何使用连接表链接列和实体?