4

I added a png file using Resources.resx, its in a folder called resources. I am trying to change my main windows background to the image.

 this.Background = Properties.Resources.backGround;

gives cannot implicitly convert type System.Drawing.Bitmap to System.Windows.Media.Brush

I have tried to follow other answers that I found such as

this.Background = new ImageBrush(new BitmapImage(new Uri(@"pack://application:,,,/myapp;component/Images/icon.png")));

but I honestly cant figure out how to use the @"pack... etc" I have tried something like this

@"pack://Info Collector:,,,/myapp;component/resources/backGround.png")));

but again I cant find any good resources that explain the line.

Thank you in advanced.

lostknight
  • 109
  • 6

1 Answers1

1

A Pack URL is one that gets you to a file located within the executing app domain. You always leave the first part alone:

pack://application:,,,/

After that you put the name of the assembly followed by a semicolon. If the resource is in the using assembly, you can just put the semicolon. You then put:

component/

Followed by the "folder path" to the resource. Put it all together and you get something like:

pack://application:,,,/<assemblyName>;component/<pathToResource>

Note that your file needs a build action of "Resource" to be found this way. A more complete explanation of Pack URIs can be found on MSDN

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117