I know in this article they set the background color using the steps followed. I was wondering if there was a way of using an image instead of a Color. I tried the following but it didn’t work:
ImageBrush brush = new ImageBrush();
brush.ImageSource =
new BitmapImage(new Uri("/MyApp;component/Images/Backgrounds/myimage.jpg"));
Rootframe.Background = brush;
Has anyone seen if this is possible? Or is it restricted to Colors?
I decided to have a go and got it working. The only catch is, it’s a bit of a workaround since there seems to be some strange behaviour with the
ImageOpenedevent. Basically, theImageOpenedevent of theBrushdoesn’t get called when you assign the background to the frame. Strangely, it does get called when you assign it to an element. So I just created a hidden button and assigned the brush to that (to force theImageOpenedevent to fire). I then assigned it to the frame and it works for me. Seems like a bug, but the workaround below works for me.