无法在XAML中创建对其他项目的xmlns引用

问题描述:

我有一个这样定义的WPF项目:

I have a WPF project defined like this:


MyApp.sln
  MyAppWPF
  MyApp.Domain

在MyAppWPF项目的一个xaml文件中,我试图引用MyApp.Domain项目中定义的类。我在MyAppWPF中有一个指向MyApp.Domain的项目引用。我试图创建这样的引用:

In one of my xaml files in the MyAppWPF project I'm trying to reference a class defined in MyApp.Domain project. I have a project reference in MyAppWPF to MyApp.Domain. I am trying to create the reference like this:


<Window x:Class="MyAppWPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyApp.Domain;assembly=MyApp.Domain"
    Title="Window1" Height="305" Width="485">
    <Window.Resources>
       <local:MyClass x:Key="mine" />
    </Window.Resources>
</Window>

我收到一条错误消息,指出找不到程序集,但是我可以创建要在后面代码中引用的类的实例,所以我知道我已经正确引用了它。

I get an error saying the assembly cannot be found, however I can create an instance of the class I want to reference in the code behind, so I know I've got it referenced correctly.

我该怎么做?我需要一个强名,还是直接引用dll而不是使用项目引用?

How do I do this? Do I need a strong name, or reference the dll directly instead of using a project reference?

检查


  1. MyClass的完全限定名称为MyApp.Domain.MyClass

  2. MyClass具有默认的公共构造函数(不包含参数),以便XAML可以实例化它。