6
votes

I am developing window phone 7 application. I am new to the window phone 7 application. I want to change the background color of the entire xaml page in the window phone 7 application. I have tried the following code in the constructor of the xaml page

 this.Background = new SolidColorBrush(Colors.White);

But it is not working.

I have also added the attribute in the phone:PhoneApplicationPage tag as follows

<phone:PhoneApplicationPage 
Background="Red"

But it is also not working. Can you please provide me any code or link or any solution through which I can resolve the above issue? If I am doing anything wrong then please guide me.

3

3 Answers

8
votes

You can set the Background property of the outermost control on the page. For a default page created in WP7 that would be a Grid named Layout.

You need to change the background of the LayoutRoot if you want to see the effect:

<Grid x:Name="LayoutRoot" Background="YellowGreen">
..
1
votes

Maybe the theme does not respect the background color in the page. What you can do is add A border as a child of the page and set its background color to whatever you want.

<phone:PhoneApplicationPage> 
<Border Background="Red">
...more content here...
</Border>
</phone:PhoneApplicationPage> 
0
votes

There are some options to set background of a page or grid.

suppose your xaml page is like below

<Grid x:Name="LayoutRoot">  
  //start from here page design
</Grid>
  1. If you want to set page from xaml then use following code. There are some options to set background of a page or grid

    <Grid x:Name="LayoutRoot">  
      //start from here page design
    </Grid>
    
  2. If want to set from .cs file use below code at constructor InitializeComponent(); methods which initialize page.

    public MainPge()
    {
        InitializeComponent();
        LayoutRoot.Background = new SolidColorBrush(Colors.White);
    }
    
  3. For all pages add following code at app.xaml.cs (tested only WP8.1 silverlight)

    public PhoneApplicationFrame RootFrame { get; private set; }
    public App()
    {
       ..............
    
       RootFrame = new TransitionFrame
       { 
          Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF))
       };
    }