Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
790 views
in Technique[技术] by (71.8m points)

wpf - How to make XmlnsDefinition work on the local assembly?

I've started using the XmlnsDefinition attribute to tie together some CLR namespaces into a single xmlns for convenience in XAML.

Unfortunately, it seems that this only works when using foreign assemblies. If I have a XAML file in the same assembly as the types that are in the namespace I'm referencing from XmlnsDefinition, then the compiler gives an error about the type not existing in the xmlns I am defining.

Moving the type to a foreign assembly fixes the problem.

Is there a way to use XmlnsDefinition on an assembly and have it be used from within that assembly via XAML?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Unfortunately, no. The XAML file must be parsed before the assembly is built in order to generate the code implied by the XAML to be included in the assembly. The XAML compiler produces code behind files (the files ending in, for example, .g.cs) and these file then become part of the assembly the XAML file is contained in. Since the assembly hasn't been built yet, the XAML compiler cannot load it to determine XmlnsDeclaration attributes have been specified.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...