如何在两个项目共享的 xaml 文件中添加用户控件的引用 [英] how to add a reference of a user control in a xaml file which is shared by two projects

查看:31
本文介绍了如何在两个项目共享的 xaml 文件中添加用户控件的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解决方案中创建了一个类库(CustomMapControl),在这个类库中我创建了一个 UserControl(MapItemsControl).
现在,我向两个项目(Portogruaro & Trieste)添加了这个类库的引用.

这是我的解决方案结构.



Portogruaro 是主要项目,拥有所有文件,Trieste 几乎拥有 Portogruaro 添加的所有文件作为参考.

所以,问题是当我尝试使用 CustomMapControl 并将其从工具箱中拖放到 xaml 中时,它会构建并给出此错误

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

命名空间clr-namespace:CustomMapControl"中不存在名称MapsItemControl"

the name "MapsItemControl" doesnt exist in namespace "clr-namespace:CustomMapControl"


有时会显示这个错误


And sometimes it shows this error

元素已经是另一个元素的子元素

Element is already a child of another element


这里是xaml命名空间


Here is the xaml namespace

 xmlns:cc="clr-namespace:CustomMapControl"

这是xaml中的用户控件

and this is the user control in xaml

 <cc:MapItemsControl />      <cc:MapItemsControl />

当我从不同项目打开 xaml 文件时,错误会发生变化.我想要在其中包含此 UserControl 的 xaml 文件也在两个项目之间共享.我很确定这是一个引用问题.
我不知道如何引用 CustomMapControl 所以它适用于两个项目.

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.

推荐答案

您可能对如何在 wpf 项目中添加命名空间有疑问.而不是:

You probably have a problem with how your namespace is added in your wpf project. Instead of:

xmlns:cc="clr-namespace:CustomMapControl"

试试这个:

xmlns:cc="clr-namespace:CustomMapControl;assembly=CustomMapControl"

这篇关于如何在两个项目共享的 xaml 文件中添加用户控件的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆