使用 Blend 自定义 XmlnsDefinition
在我的项目中,我有一个定义一组 WPF 控件的程序集。我希望能够在不显式引用 XAML 代码中的程序集的情况下使用它们。这就是我使用自定义 XmlnsDefinition 的原因:
[assembly: XmlnsDefinition(
"http://schemas.microsoft.com/winfx/2006/xaml/presentation",
"MyProject.Common.WpfLibrary.Markup")]
[assembly: XmlnsDefinition(
"http://schemas.microsoft.com/winfx/2007/xaml/presentation",
"MyProject.Common.WpfLibrary.Markup")]
[assembly: XmlnsDefinition(
"http://schemas.microsoft.com/winfx/2008/xaml/presentation",
"MyProject.Common.WpfLibrary.Markup")]
它在 VS2008 中就像一个魅力。我可以直接使用标记命名空间中定义的控件。然而 Blend 似乎不喜欢它,并且在我尝试使用控件的任何地方都会给出“无效的 XAML”错误。
你有解决方法吗?
In my project, I have an assembly that defines a set of WPF controls. I want to be able to use them without referencing explicitly the assembly in the XAML code. That's why I'm using custom XmlnsDefinition:
[assembly: XmlnsDefinition(
"http://schemas.microsoft.com/winfx/2006/xaml/presentation",
"MyProject.Common.WpfLibrary.Markup")]
[assembly: XmlnsDefinition(
"http://schemas.microsoft.com/winfx/2007/xaml/presentation",
"MyProject.Common.WpfLibrary.Markup")]
[assembly: XmlnsDefinition(
"http://schemas.microsoft.com/winfx/2008/xaml/presentation",
"MyProject.Common.WpfLibrary.Markup")]
It works like a charm in VS2008. I can use controls defined in the Markup namespace directly. However Blend doesn't seem to like it, and give my an "Invalid XAML" error wherever I try to use a control.
Do you have a workaround ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于程序集中的每个 CLR 命名空间,您应该仅使用一次 XmlnsDefinitionAttribute。使用 XmlnsCompatibleWithAttribute 进行第二次和第三次分配。
You should use XmlnsDefinitionAttribute only one time for each CLR-Namespace in an assembly. Use XmlnsCompatibleWithAttribute for the 2nd and 3rd assignment.