Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is XAML(WPF) not searching in my XML namespace definitions for the controls?

I've two similar projects. One is a Silverlight project and the other one a WPF. Both of them containing some namespaces and plenty of custom user controls.

As the controls are distributed over many namespaces, I have to define quite a few namespaces, when I'm using them. So I started to define the XML namespaces in the AssemblyInfo.cs:

[assembly: XmlnsPrefix("http://ui.example.com/xaml/touch", "cui")]
[assembly: XmlnsDefinition("http://ui.example.com/xaml/touch", "example_ui.controls")]
[assembly: XmlnsDefinition("http://ui.example.com/xaml/touch", "example_ui.themes")]

Now I have to define only one namespace in each file:

xmlns:cui="http://ui.example.com/xaml/touch"

Unfortunately this only works in Silverlight. My question is, how do I get this to work in a WPF project?

In the WPF project I get errors like this:

Error   5   The tag 'LookUpField' does not exist in XML namespace
   'http://ui.example.com/xaml/touch'. Line 7 Position 14.  D:\src\prototype\lookup-control\lookup-control\MainWindow.xaml  7   14  lookup-control
like image 917
Robin Avatar asked Aug 19 '15 06:08

Robin


1 Answers

Althougth the tutorial worked for Silverlight, I believe it may be inaccurate for WPF. See accepted answer here.

I have a separate assembly with custom controls in WPF and I'm able to use the XmlnsDefinition attribute without a problem. I think the problem lies within the definitions need to exist before the assembly is built. So even though controls will show up in your designer, it can't be built because the compiler needs the definitions while compiling the XAML in BAML which are built into the assembly at a later point.

Edit

I created another WPF user control library and added the same XmlnsDefinitions you used, added the reference of the user control library to my WPF application project, used <cui:UserControl1 /> in my MainWindow.xaml and had no errors.

like image 98
Kcvin Avatar answered Oct 05 '22 11:10

Kcvin