1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【C#】【WPF】別アセンブリのクラスをWPF上で使用する

Posted at

例えばDataModel.dllというモジュールがあって、
その中のHogeというnamespace内の『HogeClass』クラスを参照したい場合。
#当然、プロジェクト参照でDataModel.dllは参照しておく

自身のプロジェクト内と同様に以下のように記載すると参照エラーになります。

xmlns:data="clr-namespace:DataModel.Hoge"
~~中略~~
<Window.Resources>
  <data:HogeClass x:Key="HogeClass"/>
</Window.Resources>

その名前空間にそんなもんは無い!とお叱りを受けます。
確かに参照にも追加しているし、namespaceも間違っていないのに…と思っていたら、
名前空間の宣言が間違っていました。
正しくは以下のようにアセンブリ名を記載する必要があります。

xmlns:data="clr-namespace:DataModel.Hoge;assembly=DataModel"

地味にハマったのでメモ。

1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?