0

次のような状況があります。

  • ProjectA は に画像を表示する必要がありUserControlます。
    プロジェクトにイメージがあります(リソースなどにすることができます)。

  • しかし、ProjectA は単なる dll です。ProjectB で (Prism 経由で) 使用されます。

したがって、ProjectA でこれを行うと、設計時に機能します (MyImage.png ファイルが "Resource" コンパイル アクションに設定されている場合)。

<Image Source="pack://application:,,,/ProjectA;component/MyImage.png"></Image>

しかし、実行時に ProjectB にコピーされるのは dll だけです (コピーしたいのはそれだけです。そのため、MyImage.png は実行中のフォルダーに存在し、画像は表示されません。

リソースにすれば埋め込めると思ったのですが、うまくいかないようです。

また、Resources.resx を使用しようとしましたが、まったく機能していないようです (または、xaml で画像をバインドする方法が見つかりません)。

イメージを dll 内に配置して、そこから参照するにはどうすればよいですか (または、ファイル システムに依存しない他の方法でイメージを取得できますか)。

4

1 に答える 1

1

I put together a WPF application with 2 projects to see if I could recreate the problem. Unforunately, it all just worked. I used the same pack uri format from your post and I was able to display the picture directly in an image control from both projects and also have the usercontrol from "Project A" show the image when put in the window on Project B. NB: I set the picture to have a build action of resource and set it to "do not copy".

Given that it works in a simple scenario my next thought is whether the problem has anything to do with the fact that you are using PRISM. I will have a look and see what I can find.

于 2012-06-13T04:38:11.373 に答える