如何在两个项目共享的 xaml 文件中添加用户控件的引用

编程入门 行业动态 更新时间:2024-10-27 09:39:20
本文介绍了如何在两个项目共享的 xaml 文件中添加用户控件的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在解决方案中创建了一个类库(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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 15:21:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1119394.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   两个   文件   项目   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!