-1

I am trying to set the background of a programmatically created Canvas, Using the following method:

Canvas Object = new Canvas();
Object.Background = new ImageBrush(new BitmapImage(new Uri("pages/Asset/Untitled 6.png", UriKind.Relative)));

This URI WOULD WORK In XAML, for setting a background image however in C# the scope seems to be in a different folder.

Some XAML With SAME URI That Works

PandaDev
  • 121
  • 11

1 Answers1

0

Maybe you forgot to write the following code in cs file:

 this.Content = Object;

And you can set the "Build Action" to "Content" and "Copy to Output Directory" to "Copy always" in the Properties of the picture.

Hui Liu-MSFT
  • 770
  • 4
  • 15
  • 1
    You would typically use an image file as assembly resource, i.e. set its Build Action to Resource and not copy it to the output directory. – Clemens Mar 03 '21 at 06:36