0

I have an Application and therefore a login dialog. The login dialog contains an image.

<Window.Resources>
  <BitmapImage x:Key="loginImage" UriSource="login.png" />
</Window.Resources>

. . .

<Image Grid.Column="0" Grid.Row="1" Source="{StaticResource loginImage}"/>

Everything worked fine until I decided to outsource the login dialog in an seperat project to use it again in other applications. In the designer, the image is still visible. But when I start the main application and call the login dialog, the image is missing. All other Content (Labels, Buttons, ...) is working fine. It is only a problem with the image.

Does anyone have a solution?

edit: Ok, now i got i working as expected. It was so simple that it hurts... The solution given by Harris was pretty fine. I only had to rebuild the entire VS solution, not only the class library project. Thanks for the help!

Lightbringer
  • 765
  • 1
  • 4
  • 16
  • Have you made sure that the file `login.png` has beed added to the VS project, and that its build action is set to `Resource`? See [here](http://msdn.microsoft.com/en-us/library/0c6xyb66(v=vs.100).aspx). – Clemens May 27 '13 at 09:01

1 Answers1

1

I think problem is that your application is looking for the image in its own files, not in the files of separate Login Project of yours.

Instead of UriSource="login.png" you should try Source="/ClassLibraryName;Component/images/login.png"

Haris Hasan
  • 29,856
  • 10
  • 92
  • 122
  • you mean the source property of the image? I tried to set it to Source="../UserDefinedDialogs/login.png". The result is the same. The image appears in the designer but not when open the window from another application. – Lightbringer May 27 '13 at 09:09
  • @Buchter Follow the format I mentioned. First assembly name of login project and then the image. Don't do ../.. – Haris Hasan May 27 '13 at 09:24
  • Ok, i tried your Format "Source="/UserDefinedDialogs;Component/login.png" " but it doesn't fix the problem. The behaviour is still the same: Working in designer but not in compiled application. – Lightbringer May 27 '13 at 13:29
  • @Buchter This should work. Otherwise, one workaround could be to place the images in the main app rather than other project. But that's not an ideal solution – Haris Hasan May 27 '13 at 15:10
  • now i got it working using `Source="pack://siteoforigin:,,,/Images/login.png"` But this solution isn't what i want because the login.png needs to be stored as a file ind the output directory. Here http://stackoverflow.com/questions/2271863/reference-images-stored-in-external-dll-using-wpf someone had the same problem, but he fixed it with the format you mentioned. I can't understand why it dont't work in my project. If anyone has other hints for me, i woult be very grateful! – Lightbringer May 28 '13 at 07:15