C # WPF Window Background

I added a png file using Resource.resx, it is in a folder called resources. I am trying to change the background of my main window to an image.

 this.Background = Properties.Resources.backGround;

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

I tried to execute other answers that I found, for example

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

but I honestly can't figure out how to use @ "pack ... etc." I tried something like this

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

but again I cannot find good resources that explain the line.

Thank you for the advanced.

+4
source share
1 answer

The package URL is the one that takes you to a file located in the domain of the executable application. You always leave the first part:

pack://application:,,,/

, . , . :

component/

" " . , - :

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

, "", . URI Pack MSDN

+1

Source: https://habr.com/ru/post/1663286/


All Articles