Friday, March 13, 2009 4:56 PMI get a compiler error when I try to use the XmlnsDefinition attribute.
How to reproduce:
1) Create a WPF Application: WPFLocalization
2) Add a new class: Test.cs
3) Edit the Window1.xaml file
4) Now try to build and you should get the mentioned compiler errror:
Cannot find the type 'Test'. Note that type names are case sensitive.
5) Change the xmlns:local definition in the Window1.xaml file
6) The build should work now.
Why doesn't work my approach with the XmlnsDefinition attribute?
Friday, March 13, 2009 5:20 PMUnfortunately, WPF does not support this within the same assembly. I'm not sure why, but based on the MSDN description, the only thing I can speculate is that they designed it to only search referenced assemblies, and it doesn't search the source assembly.
This link to the Programming WPF book confirms this, unfortunately:
If anyone else knows why this is, and if its going to be fixed in future versions of WPF, please speak up.
Hope this helps,
Brian Schwalm • www.anythinksolutions.com
- Marked As Answer by Tao Liang Thursday, March 19, 2009 5:57 AM
Monday, March 26, 2012 10:46 AM
The root cause that prevents the usage of the XmlnsDefinition in the same namespace is that, 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.
Wednesday, February 06, 2013 9:20 AM
Well, but the compiler wouldn't need to load anything else, it could just start evaluating the attributes it's currently building. I still don't get it why this should not be possible. After all, it's just a mapping. There's aliases for everything all around and they work fine. Still looks pretty much like stupid design.