项目 A 无法引用项目 B 中的类 [英] Project A can't reference a class in Project B

查看:23
本文介绍了项目 A 无法引用项目 B 中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在我的解决方案中,我有两个项目.AB.

在项目 A(我的视图项目)中,我添加了一个指向 B(我的 ViewModels 项目.)的程序集引用/p>

所以在代码后面,在项目 B 中找到一个类就可以了.

使用 ViewModels.Appearance.Themes

当我尝试在 XAML 中查找时出现问题;

xmlns:local="clr-namespace:ViewModels.Appearance.Themes;assembly=ViewModels">

Intellisense 似乎将其检测为有效位置,但是当我尝试使用该命名空间中的类时...

<矩形 x:Key="WindowBackgroundContent" x:Shared="false" ><矩形.填充><ImageBrush local:BingImage.UseBingImage="True" Opacity=".3" Stretch="UniformToFill"/></矩形填充></矩形>

智能感知告诉我:

<块引用>

未在类型中找到可附加属性UseBingImage"'必应图片'.

似乎使其工作的唯一方法是 BingImage.cs 类是否具有直接位于项目 B 根目录中的命名空间.但我并不完全适应这里的标准惯例.

关于如何解决这个问题有什么建议吗?

解决方案

当您在 XAML 中添加引用时,尝试重建您的项目一次以重新编译所有内容并合并引用的项目并使任何新控件可用.当文件或依赖项已更改,甚至无缘无故更改时,这是必要的.但它会解决您的问题.

So in my solution I've got two projects. A and B.

In project A (My views project), I've added an assembly reference pointing to B(My ViewModels Project.)

So in code behind, finding a class in Project B works just fine.

using ViewModels.Appearance.Themes

The issue comes when I try to find it in XAML;

xmlns:local="clr-namespace:ViewModels.Appearance.Themes;assembly=ViewModels">

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 tells me:

The attachable property 'UseBingImage' was not found in type 'BingImage'.

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?

解决方案

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屋!

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