How to make custom MarkupExtension visible/accessible from a XAML file?

1.3k views Asked by At

I have my main app which uses another project with MarkupExtension. I added the reference, I added it also in XAML file, yet when I try to use it I get error:

error MC3048: '{loc:Translate View3dDialog}' value is not a valid MarkupExtension expression. 
Cannot resolve 'Translate' in namespace 'clr-namespace:TranslationByMarkupExtension'.
'Translate' must be a subclass of MarkupExtension. Line 7 Position 9.

I have TranslationExtension which is a subclass of MarkupExtension (it is public of course).

I rebuilt entire solution -- no change.

1

There are 1 answers

1
quetzalcoatl On BEST ANSWER

I assume you've got a xmlns:loc pointing to clr-namespace:TranslationByMarkupExtension? Is that namespace in the same assembly? If so, then you may have problems with VS (not) being able to read the updated assembly, as the assembly was not (yet) build. You may try to extract the extensions to another assembly that will be compiled/build separately from the one with XAMLs.

(possible case: XAML compiler needs to read the extensions, and as they come from the current assembly, it has problems, since current assembly was not build yet, since the XAMLs are not compiled = closed cycle; do not try to fix that forcefully. it is possible, compiler can be fooled to read "old/previous" version of the assembly, but that will cause oh so many other wicked and hard to trace issues..).

If you already have it in other assembly, ensure that xmlns:loc points to clr-namespace:TranslationByMarkupExtension;assembly=MyAssemblyWithTheExtension, maybe you simply forgot the assembly part.