how to add a reference of a user control in a xaml file which is shared by two projects

笑着哭i 提交于 2021-02-05 11:31:06

问题


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.

enter image description here

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!