简体   繁体   中英

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

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 XmlnsDefinition s 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM