项目A无法引用项目B中的类 [英] Project A can't reference a class in Project B
问题描述
因此在我的解决方案中,我有两个项目。 A
和 B
。
So in my solution I've got two projects. A
and B
.
在项目<$ c中$ c> A (我的视图项目),我添加了一个指向 B
(我的 ViewModels
项目。)
In project A
(My views project), I've added an assembly reference pointing to B
(My ViewModels
Project.)
因此在后面的代码中,在Project B
中找到一个类
So in code behind, finding a class in Project B
works just fine.
using ViewModels.Appearance.Themes
当我尝试在XAML中找到它时就会出现问题;
The issue comes when I try to find it in XAML;
xmlns:local="clr-namespace:ViewModels.Appearance.Themes;assembly=ViewModels">
Intellisense似乎将其检测为有效位置,但是当我尝试在该命名空间中使用该类时...
Intellisense seems to detect it as a valid location, but when I try and use the class in that namespace...
<Rectangle x:Key="WindowBackgroundContent" x:Shared="false" >
<Rectangle.Fill>
<ImageBrush local:BingImage.UseBingImage="True" Opacity=".3" Stretch="UniformToFill" />
</Rectangle.Fill>
</Rectangle>
Intellisense告诉我:
Intellisense tells me:
在类型
'BingImage'中找不到附加属性'UseBingImage'。
The attachable property 'UseBingImage' was not found in type 'BingImage'.
使其工作的唯一方法是 BingImage.cs
类是否具有直接位于Project B
根目录中的命名空间。但是我不太愿意在这里取消标准约定。
It seems the only way to make it work is if the BingImage.cs
class has a namespace that's directly in Project B
's root. But I'm not entirely comfortable braking the standard convention here.
关于如何解决此问题的任何建议?
Any suggestions on how to fix this?
推荐答案
在XAML中添加引用时,请尝试一次重建项目,以重新编译所有内容并合并引用的项目,并使任何新控件可用。当文件或依赖项已更改,甚至没有理由时,这是必要的。但这会解决您的问题。
When you add a reference in your XAML, try to Rebuild your project once to recompile everything and to incorporate the referenced project and to make any new controls available. It is necessary when a file or a dependency has been changed, or even with no reason. But it will solve your issue.
这篇关于项目A无法引用项目B中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!