问题
I have created a class library(CustomMapControl) in the solution and inside this class library I create a UserControl(MapItemsControl).
Now, I added a reference of this class library to both projects (Portogruaro & Trieste).
Here is my solution structure.
Portogruaro is the main project and has all files, Trieste has almost all the files which Portogruaro have added as a reference.
So, the problem is when I tried to use the CustomMapControl and drag and drop it in xaml from toolbox it doenst build and give this error
the name "MapsItemControl" doesnt exist in namespace "clr-namespace:CustomMapControl"
And sometimes it shows this error
Element is already a child of another element
Here is the xaml namespace
xmlns:cc="clr-namespace:CustomMapControl"
and this is the user control in xaml
<cc:MapItemsControl /> <cc:MapItemsControl />
The error changes when I open xaml file from different projects.
The xaml file in which I want to have this UserControl is also shared between the two projects.
I am quite sure that this is a referencing issue.
I have no idea how to reference the CustomMapControl so it will work for both the projects.
回答1:
You probably have a problem with how your namespace is added in your wpf project. Instead of:
xmlns:cc="clr-namespace:CustomMapControl"
try this:
xmlns:cc="clr-namespace:CustomMapControl;assembly=CustomMapControl"
来源:https://stackoverflow.com/questions/24715684/how-to-add-a-reference-of-a-user-control-in-a-xaml-file-which-is-shared-by-two-p