当我使用 ParserContext 时,为什么 XamlReader 会抛出异常?
这有效:
XamlReader.Parse("<Pig xmlns=\"clr-namespace:Farm;assembly=Farm\"/>");
这会抛出标签“Pig”在 XML 命名空间“clr-namespace:Farm; assembly=Farm”中不存在:
var context = new ParserContext();
context.XmlnsDictionary.Add("", "clr-namespace:Farm;assembly=Farm");
XamlReader.Parse("<Pig/>", context);
为什么?
Farm 是调用应用程序。
This works:
XamlReader.Parse("<Pig xmlns=\"clr-namespace:Farm;assembly=Farm\"/>");
This throws The tag 'Pig' does not exist in XML namespace 'clr-namespace:Farm;assembly=Farm':
var context = new ParserContext();
context.XmlnsDictionary.Add("", "clr-namespace:Farm;assembly=Farm");
XamlReader.Parse("<Pig/>", context);
Why?
Farm is the calling application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所拥有的可以在 .NET 4.0 中运行,但不幸的是在 .NET 3.5 中不行。尝试改用 XamlTypeMapper:
如果要使用命名空间前缀,可以使用 XamlTypeMapper 声明 clr 命名空间到 xml 命名空间映射,然后为 xml 命名空间声明命名空间前缀。
What you have will work in .NET 4.0, but unfortunately not in .NET 3.5. Try using XamlTypeMapper instead:
If you wanted to use a namespace prefix, you could declare a clr namespace to xml namespace mapping with the XamlTypeMapper and then declare a namespace prefix for the xml namespace.