简体   繁体   English

如何为Windows Phone 7应用程序设置背景图像

[英]How to set background image for windows phone 7 application

I would like to set a background image for the entire application for Windows Phone 7. I guess the size of the image should be 480 x 800 which I have already. 我想为Windows Phone 7的整个应用程序设置背景图像。我想图像的大小应该是480 x 800。

Should it be set inside App.xaml or WMAppManifest.xaml ? 是否应在App.xaml或WMAppManifest.xaml中设置? If so, please point me to a code sample. 如果是这样,请指出一个代码示例。

Have you tried this way? 你尝试过这种方式吗?

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;
    }

I don't think you need to set a background image for each page. 我认为您无需为每个页面设置背景图像。 If you add this snippet to App.xaml : 如果将此代码段添加到App.xaml中:

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

And change the Grid configuration in MainPage.xaml to : 并将MainPage.xaml中的Grid配置更改为:

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

Your image should be displayed on all pages of your app. 您的图片应显示在应用程序的所有页面上。

There is no way to set a background image globally. 无法全局设置背景图像。 You need to set it for each page. 您需要为每个页面设置它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM