My goal is to set a background picture for each page.
Consider this structure…
/Images/AppBackground.jpg
/App.xaml
/MainPage.xaml
/Page2.xaml
My first try was setting it on the rootframe as suggested elsewhere on this site… 😉
App.xaml.cs
ImageBrush brush = new ImageBrush
{
ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Images/AppBackground.jpg", UriKind.Relative)),
Opacity = 0.5d
};
this.RootFrame.Background = brush;
This will give me an error:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
I tried with and without the starting /, tried UriKind.Absolute, And without a UriType parameter, all will give me the same error. The Image AppBackground.jpg has Build Action Content.
Below code will work just fine.
MainPage.xaml
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush ImageSource="/Images/AppBackground.jpg"></ImageBrush>
</Grid.Background>
...
But that’s not what I want, I don’t want to set it for each page…
Anyone any idea what I’m screwing up? 😉
Crap. Wrong place; I was to early. In the constructor, it will simple overwrite the
Backgroundsetting…If I execute it at a later point, it’ll work just fine… 🙂