2012-07-03 129 views

回答

0

無法全局設置背景圖像。您需要爲每個頁面設置它。

3

您是否試過這種方式?

private static void SetAppBackground(string imageName) 
    { 
     var app = Application.Current as App; 
     if (app == null) 
     return; 

     var imageBrush = new ImageBrush 
       { 
        ImageSource = new BitmapImage(new Uri(imageName, UriKind.Relative)) 
       }; 
     app.RootFrame.Background = imageBrush; 
    } 
+0

我應該在哪裏調用這個方法? – bragboy

+0

在你的page.xaml中 – coder

1

我不認爲你需要爲每個頁面設置一個背景圖像。如果這個片段添加到的App.xaml:

<ImageBrush x:Key="imgKey" ImageSource="/Images/imgName.png" /> 

而且在MainPage.xaml中更改網格配置:

<Grid x:Name="LayoutRoot" Background="{StaticResource imgKey}"> 

您的圖片應該在你的應用程序的所有頁面上顯示。

相關問題