2012-07-03 133 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}"> 

您的图片应该在你的应用程序的所有页面上显示。

相关问题