I am trying to fill a rectangle with an image, the image is stored in a folder Images in the root of my project. So BrushesAndPens/Images/oog.png
Now when I add the image to a rectangle via Xaml this works fine but when I do it dynamically it finds the path but after that throws an Exception error. Code and error below. I am pretty sure my code is correct and the the image is in the correct folder.
The code:
ImageBrush imgBrush = new ImageBrush();
imgBrush.ImageSource = new BitmapImage(new Uri(@"Images/oog.png", UriKind.Relative));
Rect6.Fill = imgBrush;
The Exception: