Reputation: 10081
I have two clrnamespaces that I need to access from a WPF Window, which have a clash in names
xmlns:ns1="clr-namespace:Namespace1.Namespace2.Namespace3.Namespace4;assembly="
xmlns:ns2="clr-namespace:Namespace2;assembly=Namespace2"
When I go to use anything from Namespace2 such as
<Canvas>
<ns2:MyControl ... />
</Canvas>
I get the following compile error
The type or namespace name 'MyControl' does not exist in the namespace 'Namespace1.Namespace2' (are you missing an assembly reference?)
I know the naming of the namespaces aren't very good, but changing the former would require moving away from the structure used elsewhere in the system and changing the latter would require changes to other parts of the system.
Does anyone have any suggestions for ways round this?
Upvotes: 1
Views: 425
Reputation: 12540
If you can't find a solution using "xmlns:" then you could consider using XmlnsDefinition
to map multiple clrnamespaces into an XML namespace identified by a URI, and then use that URI to refer to the set of clr namespaces.
Put an XmlnsDefinition
into the AssemblyInfo.cs
of each assembly that contains those CLR types you want to group.
[XmlnsDefinition("http://www.mycompany.com/appname", "Namespace1.Namespace2.Namespace3.Namespace4")]
[XmlnsDefinition("http://www.mycompany.com/appname", "Namespace2")]
Then in your XAML you can do:
xmlns:ns="http://www.mycompany.com/appname"
and it should then allow you to access the types using a common prefix.
On the otherhand maybe you forgot to add a reference to the Namespace2 DLL to your project?
If none of the above works, can you describe your project structure a bit more e.g. can you show the MyControl code...where it lives...and also show the namespace statements of the code.
Upvotes: 1