WPF中映射clr namspace

原文: WPF中映射clr namspace

1. xaml中直接映射为prefix

xmlns:prefix="clr-namespace:MyApplication.Modules.Entity;assembly=MyAssembly".

2.通过XmlnsDefinitionAttribute在Assembly源码中定义:

在Assembly的AssemblyInfo.cs中添加assembly level的attribute将clr namespace映射为xml namespace.

[assembly:XmlnsDefinition("http://mynamespace.codelife.com", "MyApplication.Modules.Entity")]

然后在xaml中将xml namespace映射为prefix

xmlns:prefix="http://mynamespace.codelife.com".

通过第二种方式映射的好处在于可以将多个clr namespace映射为同一个xml namespace。但是貌似在应用XmlnsDefinition的当前assembly无法使用映射的xml namespace.

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/10261659.html
CLR