私の目標は、各ページの背景画像を設定することです。この構造を考えてみてください...
/Images/AppBackground.jpg
/App.xaml
/MainPage.xaml
/Page2.xaml
私の最初の試みは、このサイトの他の場所で提案されているように、ルートフレームに設定することでした... ;)
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;
これは私にエラーを与えるでしょう:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
開始の有無にかかわらず試してみました 、 を/
試しましUriKind.Absolute
た 、そしてUriType
パラメーターなしでは、すべて同じエラーが発生します。イメージAppBackground.jpg
には Build Action がありContent
ます。
以下のコードは問題なく動作します。
MainPage.xaml
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush ImageSource="/Images/AppBackground.jpg"></ImageBrush>
</Grid.Background>
...
しかし、それは私が望むものではありません。各ページに設定したくありません...
私が何を台無しにしているのか誰にも分かりますか?;)